IP & Network

From Pulsed Media Wiki
Revision as of 13:49, 12 May 2025 by Gallogeta (talk | contribs) (Linux: Guides: Information)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Checking Server IP Address

Commands to find the IP addresses configured on the Linux server you are currently logged into (via Terminal or SSH).

  • ip addr show or the shorter ip a: Displays detailed information about all network interfaces and their assigned IP addresses (IPv4 and IPv6). This is the modern standard command.
ip addr show
ip a
  • hostname -I: Shows only the IP address(es) associated with the server's hostname configured on active interfaces. Useful for a quick view of primary IPs.
hostname -I
  • ifconfig: (Legacy) Older command to display network interface configuration. It might not be installed by default on newer Linux distributions but is still common.
ifconfig

Identifying Connected Client IPs (e.g., via SSH)

Commands to see which remote IP addresses are currently connected to your server.

  • who: Shows who is currently logged in, typically including the source IP address or hostname for remote SSH sessions.
who
  • w: Similar to who but provides more detailed information about what each user is doing. Also shows the source IP ('FROM' column).
w
  • ss -tn: Shows active TCP connections ('s'ocket 's'tatistics). You can filter this to see who is connected to specific ports, like the SSH port (usually 22). The 'Peer Address:Port' column shows the connected client's IP and source port.
ss -tn src :22

(Replace ':22' with the actual SSH port if it's non-standard. If ss is unavailable, you might use the older netstat -tn).

Network Troubleshooting (From Home/Client to Server)

Commands typically run from your local machine (e.g., home computer) to test connectivity to the remote server. Replace [server_ip_or_hostname] with the actual IP address or domain name of the server you want to test.

  • ping [server_ip_or_hostname]: Sends ICMP echo requests ("pings") to the server to check basic reachability and measure round-trip time (latency). Press Ctrl+C to stop.
ping [server_ip_or_hostname]
  • traceroute [server_ip_or_hostname]: Shows the network path (sequence of routers or "hops") that packets take to reach the server from your machine. Helps identify where network delays or connection failures might be occurring.
traceroute [server_ip_or_hostname]

(On some Linux systems, the command might be tracepath. On Windows, use tracert).

  • mtr [server_ip_or_hostname]: (My Traceroute) Combines ping and traceroute into a single, continuously updating diagnostic tool. Provides ongoing statistics for each hop. Often needs to be installed first (e.g., sudo apt install mtr or sudo yum install mtr). Press 'q' to quit.
mtr [server_ip_or_hostname]
  • nc -zv [server_ip_or_hostname] [port]: (Netcat) Tests if a specific TCP [port] (e.g., 80 for HTTP, 443 for HTTPS, 22 for SSH) is open and listening on the server without actually transferring data ('z'ero-I/O mode, 'v'erbose). A "succeeded" message indicates the port is open from your location.
nc -zv [server_ip_or_hostname] 22
  • telnet [server_ip_or_hostname] [port]: Attempts to establish a basic TCP connection to the specified [port] on the server. If it connects (often showing a "Connected to..." message), the port is likely open. Type Ctrl+] then 'quit' to exit, or it might exit automatically if the connection fails. May need to be installed.
telnet [server_ip_or_hostname] 22
  • dig [server_hostname] or nslookup [server_hostname]: If you are using a hostname instead of an IP address, these commands query the Domain Name System (DNS) to see if the hostname correctly resolves to the expected IP address from your network.
dig [server_hostname]
nslookup [server_hostname]