It is recommended to set with the nmcli or nmtui command.
It is also possible with the ifcfg-* file.
/etc/sysconfig/network-scripts/ifcfg-*
# systemctl restart NetworkManager # nmcli networking off && nmcli networking on
# nmcli c reload <- If you change the configuration file manually # nmcli c down ens160 && nmcli c up ens160
/etc/sysconfig/network-scripts/ifcfg-*
| Option | Explanation |
|---|---|
| DEVICE | the name of the physical device |
| BOOTPROTO | none : No boot-time protocol should be used. Static IP use 'none'. dhcp : The DHCP protocol should be used. bootp : The BOOTP protocol should be used. 'STATIC' is invalid parameter. if you use 'STATIC', it see 'NONE'. |
| ONBOOT | yes : This device should be activated at boot-time. no : This device should not be activated at boot-time. |
| IPADDR | IP address. |
| NETMASK | the netmask value. |
| USERCTL | yes : Non-root users are allowed to control this device. no : Non-root users are not allowed to control this device. |
| HWADDR | the hardware address of the Ethernet device in the form AA:BB:CC:DD:EE:FF. |
| SLAVE | yes : This device is controlled by the channel bonding interface specified in the MASTER directive. no : This device is not controlled by the channel bonding interface specified in the MASTER directive. |
| ETHTOOL_OPTS | any device-specific options supported by ethtool. |
| GATEWAY | the IP address of the network router or gateway device (if any). |
/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 BOOTPROTO=dhcp ONBOOT=yes
/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 BOOTPROTO=none ONBOOT=yes IPADDR=192.168.1.5 NETMASK=255.255.255.0 USERCTL=no
Refarence:Network - Configuration | Ubuntu
/etc/netplan/nn_xxxxx.yaml
/etc/netplan/99_config.yaml
A later loaded file will override the settings of the previously loaded file
Example
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: false
dhcp6: false
addresses: [192.168.1.50/24]
gateway4: 192.168.1.1
nameservers:
addresses: [192.168.1.1, 8.8.8.8, 8.8.4.4]
$ sudo netplan apply ## If [Enter] cannot be pressed within the specified number of seconds after reflection, ## it will return to the original setting. ## default time out is 120 seconds. $ sudo netplan try --timeout 10 <- 10 seconds
Example
network:
version: 2
renderer: networkd
ethernets:
eth0:
addresses:
- 10.10.10.2/24
gateway4: 10.10.10.1
nameservers:
search: [mydomain, otherdomain]
addresses: [10.10.10.1, 1.1.1.1]
/etc/netplan/99_config.yaml
network:
version: 2
renderer: networkd
ethernets:
enp3s0:
dhcp4: true
sudo netplan apply
/etc/network/interfaces
~]# cat /etc/network/interfaces # This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto enp0s3 iface enp0s3 inet dhcp
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto ens3 #iface ens3 inet dhcp iface ens3 inet static address 192.168.10.30 network 192.168.10.0 netmask 255.255.255.0 broadcast 10.0.0.255 gateway 192.168.10.1 dns-nameservers 192.168.10.10
Linux Network Configuration and Command