Ubuntu
Ubuntu if it is the desktop version, because the desktop version installed NetworkManager, modify the contents of the interfaces document, will not take effect, need to first modify/etc/networkmanager/ Networkmanager.conf the managed parameter in the document, set it to true, and then modify the/etc/network/interfaces file to set the static IP.
#The Primary Network Interfaces
Auto Eth0 #表示让网卡开机自动挂载eth0
Iface eth0 inet Static
Address 192.168.3.3
Gateway 192.168.3.1
Netmask 255.255.255.0
#network 192.168.3.0
#broadcast 192.168.3.255
Restart the network for it to take effect
/etc/init.d/networking restart
If you cannot restart it, use the
Ifdown eth0 && ifup eth0
Set up fixed DNS
Vim/etc/resolvconf/resolv.conf.d/base
NameServer 8.8.8.8
Execute resolvconf-u after saving
can also be through vim/etc/network/interfaces, and finally add a sentence
Dns-nameservers 8.8.8.8 4.4.4.4
Centos
/etc/sysconfig/network CentOS setting hostname and network configuration either directly with the Hostnamectl command is OK, and the hostname can be modified.
/etc/sysconfig/network-scripts/ifcfg-eth0 settings for a specific NIC
/etc/resolv.conf Setting up DNS
/etc/hosts setting the specified domain name resolution address
Device=eth0
Bootproto=static
Type=ethernet
Name= "System etho0"
broadcast=192.168.56.255
hwaddr=08:00:27:24:f8:9b
Ipaddr=192.168.56.101
Ipv6init=yes
Ipv6_autoconf=yes
netmask=255.255.255.0
network=192.168.56.1
Onboot=yes
Service Network restart
Change the NIC name to Eth0
①VIM/ETC/SYSCONFIG/NETWORK-SCRIPTS/IFCFG-ENO16777736 will Name=eth0
② Renaming a configuration file
③ disable the predictable naming convention for this, you can pass "net.ifnames=0 biosdevname=0" kernel parameters at startup. This is done by editing/etc/default/grub and adding "net.ifnames=0 biosdevname=0. In the Grubcmd_linelinux variable.
④ Run the command grub2-mkconfig-o/boot/grub2/grub.cfg to regenerate the grub configuration and update the kernel parameters.
⑤ reboot at Ifconfig view should be in effect, according to the CentOS official Wiki FAQ, if you have multiple interfaces, and want to control their device name, rather than let the kernel in its own way name, create,/etc/udev/rules.d/ The xxx-net.rules rule is necessary! Well, let's create a good rule here, too.
Note: The net rule name of the previous system is 70-persistent-net.rules, here I also define the rules by this name! (This step does not make the problem is not big.) )
⑥ Restart System
There may be a case where the service network restart fails.
①mac address binding issues. Change ifctg-eno167777 that file, MAC address forgot to change, this time delete this file in the Mac binding that line, delete/etc/udev/rules.d/70-xxx This file, this file also has about MAC address settings.
② after changing the name of the network card, remember to change the inside of the Ifcfg-eth0 devices=eno167777 Devices=eth0
Restart the NIC.
Linux sets static IP and DNS and changes the NIC name