Home / Networking

Networking basics

Check connections, log in remotely and copy files securely.

Workspace with laptop and Agenda VR3 for networking basics.
CommandUse
ip addrShow network interfaces and addresses
ping hostTest whether a host answers
ssh user@hostLog in securely to another machine
scp file user@host:Copy a file over SSH
ss -tulpnList listening ports

Firewalls

Desktop and server distributions include firewall front-ends such as ufw or firewalld. Allow only the services you need, for example SSH on a server.

Routes, gateways and name lookups

An address on an interface is only part of the picture. To reach another machine, Linux also needs a route. ip route shows the kernel routing table. The line starting with default via is your usual way off the local network. If you have both Ethernet and Wi-Fi, ip route get 203.0.113.10 is handy: it shows which interface, source address and gateway Linux would pick for that destination.

Name lookups are separate from raw connectivity. getent hosts hostname asks the system resolver for an address using the same rules that most programs use. If a remote IP answers but getent fails, the network path is probably fine and the problem is DNS or local name configuration.

On many current distributions, resolvectl status shows which DNS servers and search domains are in use. On others, /etc/resolv.conf still shows the active resolver settings. /etc/hosts is also worth knowing about. It lets you pin a small set of names to fixed addresses, which can be useful for lab machines or small embedded devices. Keep entries simple and comment them clearly, otherwise old overrides are easy to forget. The order of sources, such as files before dns, is usually set in /etc/nsswitch.conf, which is why an /etc/hosts entry can override DNS. For a refresher on reading command output, see Command line. If a route or resolver change has odd side effects, the checks on Troubleshooting help narrow it down.

A quick troubleshooting sequence

When a connection fails, work from nearest to farthest. It avoids guessing and stops you changing three things at once.

  • Check link state with ip link. An interface that is UP but not LOWER_UP often means no carrier: a cable issue, a switch port problem or Wi-Fi that is not associated.
  • Check addressing with ip -br addr. The brief format is easier to scan than full ip addr, especially on a system with several virtual interfaces.
  • Check the default gateway from ip route, then test it directly with ping -c 3 <gateway-ip>. If the gateway does not answer, there is little point testing anything beyond it.
  • Check a remote address by IP first, for example ping -c 3 <remote-ip>. If that works, test the name with getent hosts hostname. This separates routing problems from name resolution problems.
  • If the host is reachable but an application still fails, test the service rather than the machine. nc -vz host 22 checks whether a TCP port can be opened, and ssh -v user@host gives useful connection details for SSH.
  • On the local machine, ss -tn state established shows current TCP sessions and can confirm whether a connection was made and then dropped.
  • If packets seem to disappear somewhere beyond the first hop, tracepath host can show where the path stops. It is often installed by default when traceroute is not.

Write down the first step that fails. That single note often tells you whether to look at cabling, Wi-Fi, DNS, a route, or the service itself. It also makes later fixes easier to explain to someone else.

SSH keys and safer remote access

If you log into the same machine often, SSH keys are more practical than typing a password every time. Generate a key pair with ssh-keygen -t ed25519. That creates a private key, which stays on your machine, and a public key, which you install on the server. The easiest method is usually ssh-copy-id user@host. If that tool is not available, append the contents of your .pub file to ~/.ssh/authorized_keys on the remote side.

A few points matter in practice:

  • Pay attention to the host key on the first connection. SSH uses it to prove you are talking to the same machine next time. If the fingerprint changes unexpectedly, stop and confirm why before accepting it.
  • Permissions matter. OpenSSH normally expects ~/.ssh to be 700 and authorized_keys to be 600; loose permissions can cause key login to be ignored. This ties in with Users & permissions.
  • Put repeated settings in ~/.ssh/config to save typing. For example:
Host vr3
    HostName 192.168.0.50
    User user

After that, ssh vr3 and scp notes.txt vr3: use the saved details.

  • Use a passphrase on keys that leave your desk, especially on laptops and small devices. For unattended scripts, create a separate key with only the access that job needs.

SSH is simple to start with, but it is also part of your security boundary. Review broader hardening choices on Security, especially if you expose SSH beyond a trusted local network.