Consider setting up the network in Linux Ubuntu.
I’ll give an example of commands for viewing information about network interfaces:
ifconfig
ifconfig -a
ifconfig eth0
ip a
ip -6 a
ethtool eth0
ethtool -i eth0
ethtool -k eth0
ethtool -S eth0
lshw -C network
lspci | grep Ethernet
netstat -st
netstat -s counter
netstat -ntl
cat /sys/class/net/eth0/operstate
ip -d -s link list dev eth0
ip -s -s link show
Example of enabling/disabling network interfaces:
sudo ifconfig eth0 up
sudo ifconfig eth0 down
sudo ifconfig wlan0 up
sudo ifup ens1f0
sudo ifdown ens1f0
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
dhclient eth0
dhclient enp0s3
cat /var/lib/dhcp/dhclient.leases
Manual assignment of settings (reset after reboot):
sudo ifconfig eth0 inet 192.168.0.2 netmask 255.255.255.0
sudo ifconfig eth0:0 inet 192.168.3.2 netmask 255.255.255.0
sudo ifconfig eth0:1 inet 192.168.10.1 netmask 255.255.255.0
You can remove all IP from the eth0 interface like this:
sudo ip addr flush dev eth0
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
address 192.168.0.2
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1
dns-nameservers 192.168.0.1
auto eth1
iface eth1 inet static
address 10.0.0.2
netmask 255.255.255.0
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.
Note that in newer versions of Linux, the network is configured via Netplan.
DNS addresses are added to the configuration file /etc/resolv.conf and the /etc/resolvconf/ directory, each with a new line, thus:
nameserver 192.168.0.1
nameserver 8.8.8.8
You can view / add / remove the default route as follows:
sudo route add default gw 192.168.1.1
sudo route del default gw 192.168.1.1
Delete network:
sudo route del -net 238.1.0.0/16
View the routing table as follows:
sudo ip route show
sudo ip route show 172.16.0.0/16
ip route get 172.16.0.5
sudo route
sudo route -n
sudo netstat -rn
sudo cat /proc/net/route
Viewing IPv6 routes:
ip -6 route
ip -6 route show t all
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 172.16.0.0/16 gw 10.0.0.1
sudo route add -net 172.16.0.0/16 dev eth0
sudo route add -host 192.168.0.1 gw 172.16.0.1
For example, with the specified route, you can delete packets:
sudo ip route add blackhole 10.10.0.0/24
You can add routes to a separate table, for example, we will add the default route to everyone, and address 192.168.5.12 will specify your default route:
sudo route add default gw 192.168.1.1
sudo ip rule add from 192.168.5.12 lookup 4
sudo ip route add default via 10.0.2.1 table 4
Restarting Network Services:
sudo /etc/init.d/networking restart
Either restart the server:
sudo reboot
In the case of packet loss with large traffic or if the shaper is not working properly, then you can try to disable offload:
ethtool -K eth0 tso off
ethtool -K eth0 gro off
ethtool -K eth0 gso off
Or so:
ethtool -K ens2f1 tso off gro off gso off
Let’s see what offload is enabled (by default all are enabled), for example generic-segmentation-offload – this is abbreviated to “gso”:
ethtool --show-offload eth0
To see if the network card interrupts are correctly distributed over the processor cores, you can use the command:
grep eth0 /proc/interrupts
An example of viewing an ARP table (-d to delete a record):
arp -an
arp -an | wc -l
arp -i eth0
See also my articles:
- Configuring VLANs in Ubuntu
- How to configure networking with Netplan
- How to change gateway
- Renaming Network Interfaces
- How to view information about the network adapter in Linux
- Network interface in Linux without IP address
- Creating dummy interfaces on Linux
- Ubuntu IP Masquerading (NAT)
- Changing TX and RX network interface buffers in Linux
- Changing txqueuelen on Linux
- The reason for increasing RX overruns on the network adapter
- nload – monitoring network interface bandwidth
- Speed limit on network interface using TC
- Solution «TX driver issue detected, PF reset issued»
- Tuning nf_conntrack
- How to find out on which NUMA node network interfaces
- Distribution of network board interrupts across processor cores
- Installing and updating the ixgbe driver
- Intel i40e driver update
- Speedtest CLI
- Replacing a word in Linux files
- How to return ethX names to network interfaces
- How to enable or disable Proxy ARP
- Configuring OSPF in Quagga