Chapter 12

MANAGING NETWORKING

  • Ethernet interfaces begin with en

  • WLAN interfaces begin with wl

  • WWAN interfaces begin with ww

  • oN indicates that this is an on-board device and the server's firmware provided index number N for the device. So eno1 is on-board Ethernet device 1. Many servers will not provide this information.

  • sN indicates that this device is in PCI hotplug slot N. So ens3 is an Ethernet card in PCI hotplug slot 3.

  • pMsN indicates that this is a PCI device on bus M in slot N. So wlp4s0 is a WLAN card on PCI bus 4 in slot 0. If the card is a multi-function device (possible with an Ethernet card with multiple ports, or devices that have Ethernet plus some other functionality), you may see fN added to the device name. So enp0s1f0 is function 0 of the Ethernet card on bus 0 in slot 1. There might also be a second interface named enp0s1f1 that is function 1 of that same device.

ip tool

ip command can be used in order to give static ip to operating system:

# to list available devices:
ip link show

# add static ipv4 address to device ens160
sudo ip addr add 192.168.207.133/24 dev ens160

# to bring up state device ens160:
sudo ip link set ens160 up

# to add ipv4 gateway to device:
sudo ip route add default via 192.168.207.1

nmcli tool

Usecase example, To add a new network connection named "mylaman2" and configure it to use the ens160 device with a static IP address of 192.168.207.129/24 and a gateway of 192.168.207.1, you would generally follow these steps on a Linux system using the NetworkManager command-line tool (nmcli). Here's how you can do it:

nmcli con add type ethernet con-name mylove ifname ens160
nmcli con modify mylove ipv4.addresses 192.168.207.129/24
nmcli con modify mylove ipv4.gateway 192.168.207.1

# above 2 commands can be given via oneliner:
nmcli con mod mylove ipv4.addresses "192.168.207.129/24 192.168.207.1"
# for ipv6
nmcli con mod mylove ipv6.address "2001:db8:0:1::a00:1/64 2001:db8:0:1::1"


nmcli con modify mylove ipv4.method manual
nmcli con up mylove
nmcli con show mylove

# replace dns entry:
nmcli con mod ID ipv4.dns 8.8.8.8

# add secondary dns entry:
nmcli con mod ID +ipv4.dns 8.8.4.4

# if DHCP is actual, it rewrites /etc/resolv.conf. to disable this:
nmcli con mod "mylove" ipv4.ignore-auto-dns yes

# to enable newly created connection autostart. This makes another not show up.
nmcli con mod "mylove" connection.autoconnect yes
nmcli con mod "notlove" connection.autoconnect no


# to delete connection:
nmcli con del static-ens3

In case you need to change the ipv4 address of currently active connection:

nmcli con modify mylove2 ipv4.addresses 192.168.207.131/24
sudo nmcli con down mylove2
sudo nmcli con up mylove2

ifcfg scripts

Note: ifcfg configuration should be added, but I was lazy.

We can also add new connection via this method:

sudo vim /etc/sysconfig/network-scripts/ifcfg-alimuellim
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=alimuellim
DEVICE=ens160
ONBOOT=yes
IPADDR=192.168.207.131
PREFIX=24
GATEWAY=192.168.207.1
sudo nmcli con reload # or command below
sudo systemctl restart NetworkManager

nmcli con down "alimuellim"
nmcli con up "alimuellim"
COMMAND
PURPOSE
nmcli dev status

Show the NetworkManager status of all network interfaces.

nmcli con show

List all connections.

nmcli con show name

List the current settings for the connection name.

nmcli con add con-name name

Add a new connection named name.

nmcli con mod name

Modify the connection name.

nmcli con reload

Reload the configuration files (useful after they have been edited by hand).

nmcli con up name

Activate the connection name.

nmcli dev dis dev

Deactivate and disconnect the current connection on the network interface dev.

nmcli con del name

Delete the connection name and its configuration file.

Last updated

Was this helpful?