Skip to Content

Linux network commands

Network command in Linux

ifconfig Display network interface configuration.
ip addr Show IP addresses and network interfaces.
ip route Display the routing table.
ping Test network connectivity to a host.
traceroute Trace the route packets take to a host.
netstat Show network statistics and connections.
ss Similar to netstat, show socket statistics.
nslookup Query DNS for specific domain information.
dig DNS lookup utility for querying DNS servers.
host DNS lookup utility for querying DNS servers.
wget Download files from the internet.
curl Transfer data with URLs using various protocols.
ssh Securely connect to a remote server.
telnet Connect to a remote host using Telnet protocol.
ifup / ifdown Bring up or down a network interface.
route Show or modify the IP routing table.
iptables Configure firewall rules.
nmap Network scanner for discovering open ports.

Network FAQ in Linux

How can I check my network interface name?
Use the ifconfig or ip addr command to list all network interfaces. The interface names appear as eth0, enp2s0, etc.

How do I check my IP address?
Run ip addr or ifconfig to display the IP addresses associated with each network interface.

What command can I use to check network connectivity to a host?
Use ping to test if a host is reachable over the network. Example: ping

How can I find the route packets take to a host?
Use traceroute or traceroute6 to trace the path packets take to reach a host. Example: traceroute

How do I check the network connection status and active connections?
Use netstat or ss command to view network connections and statistics. Example: netstat -tuln

How can I diagnose DNS issues?
Use nslookup, dig, or host to query DNS servers and troubleshoot DNS resolution problems.

How do I configure firewall rules?
You can use iptables or ufw (Uncomplicated Firewall) to set up and manage firewall rules.

How can I check the status of network services?
Use systemctl to check the status of network-related services like networking, NetworkManager, etc.

How do I test a remote server’s port availability?
Use telnet or nc (netcat) to check if a specific port on a remote server is open. Example: telnet 80

How can I check network link status and statistics?
Use ethtool to display network interface link status, speed, and statistics. Example: ethtool eth0

How do I change my IP address in Linux? You can use the ifconfig or ip command to change the IP address of a network interface. Example: sudo ifconfig eth0

How can I set a static IP address in Linux? Edit the network configuration file (e.g., /etc/network/interfaces or /etc/sysconfig/network-scripts/ifcfg-eth0). Example: Edit /etc/sysconfig/network-scripts/ifcfg-eth0: NAME=eth0

How do I change the hostname of my Linux system? Edit the /etc/hostname file and update the hostname, then reboot the system or use hostnamectl command. Example: sudo nano /etc/hostname Example: Update with desired hostname Example: sudo hostnamectl set-hostname newhostname

How can I configure a network bridge in Linux? Use tools like brctl or nmcli to create and manage network bridges for virtual machines or containers. Example: sudo nmcli connection add type bridge con-name br0 ifname br0

How do I change the DNS server in Linux? Update the /etc/resolv.conf file with the desired DNS server IP addresses or use nmcli to manage network connections. Example: sudo nano /etc/resolv.conf Example: Add nameserver

How can I change the default gateway in Linux? Use the ip command or edit the network configuration file to change the default gateway IP address. Example: sudo ip route add default via

How do I set up a virtual network interface in Linux? Use the ifconfig or ip command to create a virtual network interface with the :X notation (e.g., eth0:1). Example: sudo ifconfig eth0:1 netmask

How can I change the MTU size in Linux? Use the ip command to set the MTU size of a network interface. Example: sudo ip link set eth0 mtu 1500

How do I configure a proxy server in Linux? Edit the system-wide environment variables or configure proxy settings for specific applications like apt or curl. Example: Set HTTP_PROXY and HTTPS_PROXY environment variables or edit /etc/apt/apt.conf

How can I enable or disable IPv6 in Linux? Use sysctl to enable or disable IPv6 support in the kernel. Example: sudo sysctl net.ipv6.conf.all.disable_ipv6=1 Example: sudo sysctl net.ipv6.conf.all.disable_ipv6=0

Network configuration file in Linux

/etc/network/interfaces This file is used for network interface configuration on Debian-based systems (e.g., Ubuntu).
/etc/sysconfig/network-scripts/ifcfg-eth0 Configuration file for network interface eth0 on Red Hat-based systems (e.g., CentOS, Fedora).
/etc/netplan/*.yaml YAML files used for network configuration on modern Ubuntu systems with Netplan.
/etc/resolv.conf Contains DNS (Domain Name System) configuration, specifying name servers to resolve domain names.
/etc/hostname This file stores the hostname of the system.
/etc/hosts Maps IP addresses to hostnames, used for local hostname resolution.
/etc/nsswitch.conf Configuration file that determines the order of resolution for various services (e.g., hosts, DNS).
/etc/NetworkManager/NetworkManager.conf Configuration file for NetworkManager, a daemon managing network connectivity on many Linux systems.
/etc/sysctl.conf Contains kernel parameters that can be adjusted to optimize network performance and behavior.

Troubleshoot network issues in Linux

Check Physical Connection Ensure that all network cables are properly connected, and the network interface (e.g., Ethernet adapter) is recognized by the system.
Check Network Interface Use ifconfig or ip addr to verify the network interface’s status and IP address assignment.
Check Network Configuration Review the network configuration files (e.g., /etc/network/interfaces, /etc/sysconfig/network-scripts/ifcfg-eth0) for correctness.
Check DNS Configuration Verify the DNS settings in /etc/resolv.conf and ensure DNS servers are reachable.
Check Default Gateway Use ip route or netstat -r to check the default gateway and verify that it is reachable.
Check Network Services Confirm that necessary network services (e.g., NetworkManager, dhclient, systemd-networkd) are running and configured properly.
Test Network Connectivity Use ping to test connectivity to local and remote hosts.
Trace Route Use traceroute or traceroute6 to identify the route packets take to reach a specific host or diagnose network latency.
Check Firewall Rules Inspect firewall configurations (iptables, ufw) to ensure they aren’t blocking necessary network traffic.
Check Network Tools Use tools like netstat, ss, ip, ethtool, tcpdump, or wireshark to analyze network traffic and identify anomalies.

These steps provide a systematic approach to troubleshooting common network issues in Linux. By following these procedures, you can identify and resolve problems related to network connectivity, configuration, and services effectively.