To view network adapter drivers, execute:
lspci -k | grep -A2 Ethernet
The list of network interfaces can be seen with the command:
ls /sys/class/net
Let's assume our interface is named "ens33".
Interface configuration using the "ip" utility.
ip link show #View network connections
ip -s l #View statistics on sent/received packets
ip address show #View TCP/IP configuration
ip link set dev ens33 up #Enable the interface if it was disabled
ip address flush dev ens33 #Reset interface configuration
ip addr add 192.168.0.5/24 broadcast + dev ens33 #Set IP and mask
ip addr del 192.168.0.5/24 dev ens33 #Delete IP and mask (in case of error)
ip route show #View routing table
ip route add default via 192.168.0.1 dev ens33 #Set default gateway
ip route delete default #Delete default gateway
ip route add 192.168.10.0/24 via 192.168.0.254 dev ens33 #Add a route
ip route del 192.168.10.0/24 dev ens33 #Delete a route
echo "nameserver 192.168.0.1 8.8.8.8" | sudo tee /etc/resolv.conf #Add DNS
These settings are temporary and will work until the OS is rebooted.
Configuring the network subsystem using the "ifupdown" method (used by default when installing without a GUI).
1. Install the package and start the service (if the "networking" service is missing):
sudo apt-get install ifupdown
sudo systemctl enable --now networking
2. To configure the interface, you need to create or edit the existing file "/etc/network/interfaces".
Specify the following parameters in the file:
For DHCP:
iface lo inet loopback
auto lo
auto ens33
iface ens33 inet dhcp
For static IP:
iface lo inet loopback
auto lo
auto ens33
iface ens33 inet static
address 192.168.1.100/24 #IP and mask
gateway 192.168.1.1 #Default gateway
up ip route add 10.0.0.0/8 via 192.168.1.200 #Static routes
metric 0
and create the file "/etc/resolv.conf" with the following content:
nameserver 192.168.0.1 #DNS1
nameserver 8.8.8.8 #DNS2
3. Restart the interface:
sudo ifdown ens33 && sudo ifup ens33
or the service:
sudo systemctl restart networking
4. Perform configuration checks:
ip address show
ip route show
If necessary to remove "ifupdown" components, execute:
sudo apt-get remove ifupdown
sudo rm -f /etc/network/interfaces
sudo rm -rf /etc/network/interfaces.d/*
sudo rm -f /etc/resolv.conf
Configuring the network subsystem "NetworkManager" (used by default when installing with a graphical interface).
1. Install NetworkManager:
sudo apt-get install network-manager
2. Enable and start the service:
sudo systemctl enable --now NetworkManager
3. Configure NetworkManager to manage all interfaces by editing the file "/etc/NetworkManager/NetworkManager.conf": in the [ifupdown] section, change the parameter value to:
managed=true
4. Configure the network interface using the terminal utility "nmtui" or from the command line with the utility "nmcli":
Viewing:
nmcli con show #View network connections
nmcli dev show ens33 #View active connection on "ens33"
nmcli con show 'Wired connection 1' #View connection parameters
Settings for DHCP:
nmcli con mod 'Wired connection 1' ipv4.method auto
nmcli con mod 'Wired connection 1' ipv4.addresses "" ipv4.gateway ""
nmcli con mod 'Wired connection 1' ipv4.dns ""
nmcli con mod 'Wired connection 1' ipv4.routes ""
nmcli con up 'Wired connection 1'
Settings for static IP:
nmcli con mod 'Wired connection 1' ipv4.addresses 192.168.0.5/24
nmcli con mod 'Wired connection 1' ipv4.gateway 192.168.0.1
nmcli con mod 'Wired connection 1' ipv4.dns "192.168.0.1 8.8.8.8"
nmcli con mod 'Wired connection 1' +ipv4.routes "192.168.10.0/24 192.168.0.254"
nmcli con mod 'Wired connection 1' ipv4.method manual
nmcli con up 'Wired connection 1'
5. Perform configuration checks:
ip address show
ip route show
If necessary to remove "NetworkManager" components, execute:
sudo apt-get remove network-manager
sudo rm -rf /etc/NetworkManager/
sudo rm -rf /var/lib/NetworkManager/
sudo rm -f /etc/resolv.conf
Configuring the network subsystem "systemd-networkd".
1. The "systemd-networkd" service is already included in "systemd", install only "systemd-resolved", add them to autostart:
sudo apt-get install systemd-resolved
sudo systemctl enable --now systemd-networkd
sudo systemctl enable --now systemd-resolved
2. Create a configuration file (the ".network" extension is mandatory):
sudo nano /etc/systemd/network/20-wired.network
Settings for DHCP:
[Match]
Name=ens33
[Network]
DHCP=ipv4
Settings for static IP:
[Match]
Name=ens33
[Network]
Address=192.168.0.5/24
Gateway=192.168.0.1
DNS=192.168.0.1 8.8.8.8
[Route]
Destination=192.168.10.0/24
Gateway=192.168.0.254
Metric=10 #Optional
3. Restart or reload the service:
sudo systemctl restart systemd-networkd
or
sudo networkctl reload
4. Perform configuration checks:
ip address show
ip route show
resolvectl
If necessary to remove "systemd-networkd" components, execute:
sudo systemctl disable --now systemd-networkd systemd-resolved
sudo apt-get remove systemd-resolved
sudo rm -rf /etc/systemd/network/*
sudo rm -f /etc/resolv.conf
General recommendations!!!
For simple server and virtual machine configurations, use "systemd-networkd", in this case, it is recommended to remove all other modules:
sudo apt-get remove ifupdown network-manager dhcpcd-base
sudo rm -f /etc/network/interfaces
sudo rm -rf /etc/network/interfaces.d/*
sudo rm -rf /etc/NetworkManager/
sudo rm -rf /var/lib/NetworkManager/
sudo rm -f /etc/resolv.conf
No comments:
Post a Comment