CentOS7 modify and set static IP and DNS
Recently, because I learned Puppet, I installed CentOS on a virtual machine and used the NAT network mode. To prevent network IP changes when the system is started again, I set static IP addresses and DNS.
Since CentOS is minimal installed, noifconfigCommand, so you can useipCommand to view.
View IP Address Allocation:
# ip addr
It is found that there is only one LOOPBACK 127.0.0.1 LOOPBACK address. After CentOS is installed, the network connection is disabled by default. The IP address and DNS settings are mainly modified in the following configuration file:
# vi /etc/sysconfig/network-scripts/ifcfg-*
Use vi because the installation is minimized without vim. The specific configuration file needs to be viewed under the network-scripts directory, usuallyifcfg-For exampleifcfg-eth0, Mine isifcfg-eno16777736For my cleanliness, I have to change this messy name, another one.ifcfg-loIs the LOOPBACK network.
# Vi/etc/sysconfig/network-scripts/ifcfg-[tab twice] ifcfg-eno16777736 ifcfg-lo
1. Editifcfg-eno16777736:
BOOTPROTO = static # Change dhcp to static (modify) ONBOOT = yes # enable this configuration on startup. Generally, in the last line (modify) IPADDR = 192.168.1.204 # static IP (ADD) GATEWAY = 192.168.1.2 # default GATEWAY. If the virtual machine is installed, it is usually 2, that is, the VMnet8 GATEWAY settings (Added) NETMASK = 255.255.255.0 # Subnet Mask (Added) DNS1 = 192.168.1.2 # DNS configuration, if the virtual machine is installed, the DNS serves as the gateway. If multiple DNS URLs are installed, the DNS will be added (added)
2. Restart the network service.
# service network restart
3. Check the network
# ip addr1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:58:14:ee brd ff:ff:ff:ff:ff:ff inet 192.168.1.204/24 brd 192.168.1.255 scope global eno16777736 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe58:14ee/64 scope link valid_lft forever preferred_lft forever
As you can see, the eno16777736 network is up. Ping a domain name to test whether DNS is OK:
# ping www.baidu.com