Networking
Most Linux systems are connected to a network as a client system, or to provide services to other systems. Knowing how to configure, monitor, and audit the network configuration is more than useful. In this section we look at the available options.
Network configuration
The system itself can’t talk with other systems if it doesn’t have any protocol to communicate. Nowadays that is mostly IP . The local configuration for the network is usually stored in /etc/network or in a network manager in /etc.
Common components that help with managing the network configuration, include:
- Netplan
- networkd
- NetworkManager
Good to know: Netplan uses a backend like networkd or NetworkManager to apply the configuration.
IP address information
To retrieve existing network information and IP in particular, we use the ip command. As this command has several subcommands, we use address in this particular case.
ip address
This output might include:
- Link name
- Status
- MTU size
- MAC address
- Any alternative name (alias)
- IP address and netmask
- IPv6 information
Gateway or router
To connect to systems outside the network, we use a gateway. This is a (virtual) router to move network packets between different networks. To see routing information, we can use the route subcommand.
ip route
DNS servers
To translate between host names and IP addresses, we use DNS . The servers to be used are typically configured within the network manager. In some cases they are defined directly in /etc/resolv.conf . In the past, this was the common way to do this, but that is changing. Still, it is good to check the configuration and see what is defined.
cat /etc/resolv.conf
When using systemd, you might even see the DNS server pointing to a local address like 127.0.0.53, meaning it uses a local service.
resolvectl status
Filtering ARP traffic with Linux arptables
Filtering ARP traffic is easy with the arptables utility. In this article we look at the possibilities of arptables and provides example of using it.
Iptables
Everything related to iptables, one of the firewall solutions on Linux. Learn how to configure, tune, and monitor iptables.
Linux DNS Tuning for Performance and Resilience
Linux DNS configuration is usually done during the installation of the system. With proper configuration and tuning, you gain performance and stability.
Linux Security Guide for Hardening IPv6
Extensive guide to help you secure your IPv6 configuration on Linux. From initial set-up to hardening the kernel with sysctl.
Nftables
Everything related to nftables, the replacement for iptables. Learn how to configure, tune, and monitor nftables.
Which Linux process is using a particular network port?
Seeing the 'address in use' error or need to find out which process is listening to a particular port on Linux? Here are the tools to find out!
Relevant networking commands
Like to learn more about the commands used in this section? Have a look at the cheat sheets or the related command page.
- cat
- ip
- resolvectl
Frequently Asked Questions
How to see the network IP address of your system on Linux?
Run the ip command to see network details and use the 'address' subcommand to see specifically the IP addresses that are defined.
How to see the IP address of your internet connection from the command line?
Use the dig command and query the myip.opendns.com hostname to see the IP address of your internet connection that performed the DNS query.
How to see which DNS server is used on Linux?
When the Linux system is using systemd, use the resolvectl command to see the active DNS server. Otherwise, have a look in /etc/resolv.conf.
How to see the number of open connections?
Run the ss command and use the '--summary' option see statistics, such as the number of open network connections.
How to see active connections and bandwidth usage?
Run the iftop command to see active connections, including bandwidth usage.
How to clear the DNS resolver cache with systemd?
To clear the systemd resolver cache use the resolvectl command with the 'flush-caches' subcommand.
How to show network TCP connection statistics and counters?
Run nstat and select all counters that start with 'Tcp' to see TCP connection information and details.
How to see errors and dropped packets on a network interface on Linux?
Run the ip command together with the statistics option and select the network interface using the 'link' subcommand to see errors and dropped packets.
How to see the default gateway on Linux?
Use the ip command together with 'route' to see routing information, including the default gateway.
How to see which process is using a port?
Run the ss command and define the source port, such as :443, to see which process is listening on that port.
How to show open network ports such as TCP and UDP?
Run the ss command and define TCP and UDP connections with at least -t and -u. Use supporting options to tune the provided information, such as using numeric values.
How to see the TTL value of a DNS record?
Run the dig command and have it show the TTL value with the help of the +ttlunits option.