Skip to Content

Top Ubuntu network commands in 2023

If you’re an Ubuntu user, there are some essential network commands that you need to know.

In this blog post, I will go over the most important Ubuntu networking commands. I will also provide a brief explanation of what each command does. So whether you’re a beginner or an experienced Ubuntu user, this post is for you!

ip: Using this command enables you to view your system’s IP address information as well as configure network interfaces.

ifconfig: This command allows you to configure network interfaces, view their settings, and check for errors.

hostname: This command displays the name of your Ubuntu server on the network.

netstat: This command displays active connections on your network and provides detailed information about each connection, including the port numbers of each end point, the protocol being used (TCP or UDP), and the state of the connection.

route: This command is used to manage routing tables, which determine how data is transmitted over a network.

traceroute: This command tracks the path that packets take from your computer to a destination on the network and can be used to troubleshoot connectivity issues.

ping: The Ping command is often used to test if two computers are able to “talk” to each other on a network.

dig: This command is used to query DNS servers for information about a given domain name. It can be used to find the IP addresses associated with a domain, as well as other detailed information.

ip command

The ip command is one of the basic commands every administrator will need in daily work, from setting up new systems and assigning IPs to troubleshooting existing systems. The ip command can show address information, manipulate routing, plus display network various devices, interfaces, and tunnels.

Here are some common use cases for the ip command.

• Displaying the IP address of a device

• Adding an additional IP address to an interface

• Enabling or disabling network interfaces

• Setting up virtual interfaces such as aliases and bridges.

To show the IP addresses assigned to an interface on your server:

[root@server ~]# ip address show 

To assign an IP to an interface, for example, enps03:

[root@server ~]# ip address add 192.168.1.254/24 dev enps03

To delete an IP on an interface:

[root@server ~]# ip address del 192.168.1.254/24 dev enps03

Alter the status of the interface by bringing the interface eth0 online:

[root@server ~]# ip link set eth0 up

Alter the status of the interface by bringing the interface eth0 offline:

[root@server ~]# ip link set eth0 down

Alter the status of the interface by changing the MTU of eth0:

[root@server ~]# ip link set eth0 mtu 9000

Alter the status of the interface by enabling promiscuous mode for eth0:

[root@server ~]# ip link set eth0 promisc on

Add a default route (for all addresses) via the local gateway 192.168.1.254 that can be reached on device eth0:

[root@server ~]# ip route add default via 192.168.1.254 dev eth0

Add a route to 192.168.1.0/24 via the gateway at 192.168.1.254:

[root@server ~]# ip route add 192.168.1.0/24 via 192.168.1.254

Add a route to 192.168.1.0/24 that can be reached on device eth0:

[root@server ~]# ip route add 192.168.1.0/24 dev eth0

Delete the route for 192.168.1.0/24 via the gateway at 192.168.1.254:

[root@server ~]# ip route delete 192.168.1.0/24 via 192.168.1.254

Display the route taken for IP 10.10.1.4:

[root@server ~]# ip route get 10.10.1.4

ifconfig command

The ifconfig command is used to configure, control and query information about your system’s IP network interfaces. It is a utility for displaying, setting and configuring network device parameters.

In preparing for this article, ifconfig still worked well on our testing system, but it was no longer installed by default. It is losing favor as ip sees more use.

Common uses of ifconfig include:

• Displaying the IP address of an interface

• Setting or changing the IP address of an interface

• Setting or changing the netmask of an interface

• Enabling or disabling network interfaces

Here are some examples of using ifconfig:

To display information about all active network interfaces:

root@server ~]$ ifconfig -a

To display information about a specific interface, such as eth0:

root@server ~]$ ifconfig eth0

To assign an IP address to an interface, for example, enps03:

root@server ~]$ ifconfig enps03 192.168.1.254 netmask 255.255.255.0

To change the MTU of an interface, for example, eth0:

root@server ~]$ ifconfig eth0 mtu 9000

To enable promiscuous mode on an interface, for example, eth0:

root@server ~]$ ifconfig eth0 promisc

hostname command

The hostname command is used to set or display the system’s host name. It is a short textual label that can be used to identify a computer on a network and as part of a network address.

Common uses of the hostname command include:

• Displaying the system’s current host name

• Setting a new host name

• Displaying the system’s domain name

• Setting a new domain name

Here are the examples of using the hostname command. To display the system’s current hostname:

root@server ~]$ hostname

To set a new hostname, for example, server-1:

root@server ~]$ hostname server-1

To display the system’s current domain name:

root@server ~]$ hostname -d

To view the FQDN (fully qualified domain name):

root@server ~]$ hostname -f

The output will be something like server-1.mydomain.com. This is the fully qualified domain name of your system. It includes both the hostname and the domain name.

route command

The route command is used to view, add or remove routes from the IP routing table. It is a powerful tool for managing and configuring networking, as it enables you to view the IP routing table and modify it according to your needs.

Common uses of route include:

• Displaying all active routes

• Adding or deleting a specific route

• Adding a default route (for all addresses) via a gateway

• Setting up static routes

Here are some examples of using route:

To display all active routes:

root@server ~]$ route -n

To add a default route (for all addresses) via the local gateway 192.168.1.254 that can be reached on device eth0:

root@server ~]$ route add default gw 192.168.1.254 dev eth0

To delete a specific route, for example, 192.168.1.0/24:

root@server ~]$ route delete -net 192.168.1.0/24

To setup a static route, for example, to the 10.10.2.0/24 network via 192.168.1.254:

root@server ~]$ route add -net 10.10.2.0/24 gw 192.168.1.254 dev eth0

traceroute command

The traceroute command is a network diagnostic tool that is used to view the route of an IP packet from one device to another. It shows each hop along the route, as well as any associated delays. This can be useful for troubleshooting network problems, such as slow response times or packet loss.

Common uses of traceroute include:

• Viewing the route of an IP packet from one device to another

• Troubleshooting network problems, such as slow response times or packet loss

• Identifying nodes with high latency in a network

Here is an example of using traceroute. To run a traceroute to the IP address 8.8.8.8:

root@server ~]$ traceroute 8.8.8.8

The output of this command will show the route of an IP packet from the local device to the specified destination, as well as associated delays and hop counts for each node in the route.

ping command

The ping command is used to check the connectivity between two networked devices. It sends an ICMP echo request packet to a specified address and waits for a response. The ping command can be used to troubleshoot network problems, such as slow response times or packet loss.

Common uses of ping include:

• Checking the connectivity between two devices

• Troubleshooting network problems, such as slow response times or packet loss

• Identifying nodes with high latency in a network

Here is an example of using ping. To check the connectivity to the IP address 8.8.8.8:

root@server ~]$ ping 8.8.8.8

The output of this command will show the response time and any associated errors or timeouts for each packet sent to the specified address.

You need to stop the ping command by pressing CTRL+C. Otherwise, it will ping until you stop it. After every ping command, it will display a summary report with the following information:

• Packets sent

• Packets received

• Minimum round-trip time

• Maximum round-trip time

• Average round-trip time

This information can be used to measure the network performance and identify any potential problems.

Also, you will see TTL, which stands for Time To Live. Ping uses a numerical TTL value to attempt to reach a given host computer via the route path. This is also known as the hop limit.

Normally, when you run a simple ping command without passing any additional parameters, Linux will ping that host for an infinite amount of time. If you want to ping a host ten times, use the following command:

[root@server ~]# ping -c 10 google.com

Use option -q to view only the ping statistics summary:

[root@server ~]# ping -c 10 google.com

On systems with multiple interfaces, you can specify the interface for the ping command to use. If the system has both eth0 and eth1 and I want to ping using the eth0:

[root@server ~]# ping -I eth0 google.com

Or use the address on the interface, assuming the interface as 10.233.201.45 as the IP:

[root@server ~]# ping -I 10.233.201.45 google.com

You can also ping and specify the IP version as either v4 or v6:

[root@server ~]# ping -4 google.com

[root@server ~]# ping -6 google.com

dig command

The dig command is a powerful network troubleshooting tool that can be used for DNS query and zone transfers. It allows you to look up information about hostnames, IP addresses, mail servers, and other types of DNS records. This can be useful for troubleshooting network issues or understanding how the DNS system works.

Common uses of dig include:

• Querying DNS records, such as A, MX, NS, SOA and TXT

• Troubleshooting DNS issues

• Understanding how the DNS system works

• Performing zone transfers

Here is an example of using dig. To query the MX record for a domain name:

root@server ~]$ dig mx google.com

The output of this command will show all the MX records associated with this domain name, as well as other related information such as the TTL (time to live) and the priority for each record. This can be useful for understanding how mail servers are configured for a domain .

You can also use the dig command to perform zone transfers, which is useful for administrators who are managing their own DNS servers. To perform a zone transfer:

root@server ~]$ dig axfr google.com

This command will transfer all of the records associated with this domain name from the master server to the local system.

dig allows you to specify additional parameters for more advanced queries, such as specifying a specific record type. For example:

root@server ~]$ dig -t txt google.com

This command will query the TXT record for this domain name. You can also query multiple domains at the same time by passing multiple domain names as arguments.

Finally, you can use the dig command to specify a specific DNS server to query. This is useful for troubleshooting DNS issues or testing configurations on specific servers:

root@server ~]$ dig google.com @8.8.8.8

This command will query the Google DNS server (8.8.8.8) for information about the domain name specified in the command.

Overall, dig is a powerful network troubleshooting tool that can be used to look up information about hostnames and IP addresses, as well as perform zone transfers and other advanced queries. It is an essential tool for network administrators who need to troubleshoot DNS issues or understand how the DNS system works.

Conclusion

These are some of the most important Ubuntu networking commands that you should be familiar with. Knowing how to use them properly can help you troubleshoot and manage your network more effectively.

If you ever have any questions about using these commands, feel free to consult the official Ubuntu documentation. With these tools, you can make your networking experience much easier and smoother!