Configuring the Network in Linux

Consider setting up the network in Linux Ubuntu.

I’ll give an example of commands for viewing information about network interfaces:

ifconfig -a
ifconfig eth0
ip a
ethtool eth0
ethtool -i eth0
ethtool -k eth0
ethtool -S eth0
ip -s -s link show
lshw -C network
lspci | grep Ethernet
netstat -st

Example of enabling interfaces:

sudo ifconfig eth0 up
sudo ifconfig eth1 up
sudo ifconfig wlan0 up

If the name of the network interface is unknown, then look it in “logical name” by typing the command:

sudo lshw -C network

To once request IP address by DHCP, execute the command:

dhclient eth0
dhclient enp0s3

Manual assignment of settings (reset after reboot):

sudo ifconfig eth0 inet netmask

For the settings not to be reset, they must be written to the configuration file:

sudo nano /etc/network/interfaces

Example content:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static

auto eth1
iface eth1 inet static

auto eth2
iface eth2 inet dhcp

In the nano editor, the Ctrl+O key combination is used to save the changes, Ctrl+X to exit.

DNS addresses are added to the configuration file /etc/resolv.conf, each with a new line, thus:


You can view / add / remove the default route as follows:

sudo route add default gw
sudo route del default gw

Delete network:

sudo route del -net

View the routing table as follows:

sudo ip route show
sudo ip route show
sudo route
sudo route -n
sudo netstat -rn
sudo cat /proc/net/route

Example of adding routes for the network through the gateway, network interface and route for a specific address through the gateway:

sudo route add -net gw
sudo route add -net dev eth0
sudo route add -host gw

For example, with the specified route, you can delete packets:

sudo ip route add blackhole

You can add routes to a separate table, for example, we will add the default route to everyone, and address will specify your default route:

sudo route add default gw
sudo ip rule add from lookup 4
sudo ip route add default via table 4

Restarting Network Services:

sudo /etc/init.d/networking restart

Either restart the server:

sudo reboot

In case of packet loss with large traffic, you can try to disable offload:

ethtool -K eth0 tso off
ethtool -K eth0 gro off
ethtool -K eth0 gso off
ethtool -K eth0 lro off

The commands at the beginning of the article, you can see which offloads are enabled (by default all are enabled), for example generic-segmentation-offload – this is abbreviated to “gso”.

To see if the network card interrupts are correctly distributed over the processor cores, you can use the command:

grep eth0 /proc/interrupts

See also:
Ubuntu IP Masquerading (NAT)
Changing TX and RX network interface buffers in Linux
Changing txqueuelen on Linux

Leave a Reply