Here, first enter /etc/sysconfig/network-scripts to view the existing configuration file:
# cd /etc/sysconfig/network-scripts
View files through ls to see the files in the file directory:
The configuration file that needs to be used here is: ifcfg-eno16777736, everyone's may be different, switch root permissions, enter through vim, and you can see the content inside:
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777736
UUID=ae05ccde-6a29-4332-b486-f3042da73ac0
DEVICE=eno16777736
ONBOOT=no
Here are the locations that need to be modified:
# modify
BOOTPROTO=static #Here talk about dhcp replaced with ststic
ONBOOT=yes #Replace no with yes
# Add
IPADDR=192.168.85.100 #Static IP
GATEWAY=192.168.85.2 #Default gateway
NETMASK=255.255.255.0 #Subnet mask
After saving and exiting, restart the network service:
# service network restart
Restarting network(via systemctl):[determine]
View current ip:
# ip addr
1: 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 forever
2: eno16777736:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:e7:b8:77 brd ff:ff:ff:ff:ff:ff
inet 192.168.85.100/24 brd 192.168.85.255 scope global eno16777736
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fee7:b877/64 scope link
valid_lft forever preferred_lft forever
3: virbr0:<NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
link/ether 52:54:00:b9:8f:6c brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
4: virbr0-nic:<BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 500
link/ether 52:54:00:b9:8f:6c brd ff:ff:ff:ff:ff:ff
You can see that the ip corresponding to eno16777736 has changed. At this time, ping 192.168.85.100 in the host to verify whether it can be pinged:
Here we restart the virtual machine after setting it up, and then use:
# ip addr
I found that the ip address of eno16777736 has changed at this time, and I have become 192.168.85.133 here. It doesn't matter here that the static IP set before is still valid, and it can still be pinged in this machine.
I say this here because the online information said that the configuration is to add a line of configuration:
NM_CONTROLLED=no
This means that the interface will be set through the configuration file, rather than managed through the network manager. "ONBOOT=yes" tells us that the system will open the interface when it starts.
The ip after setting NM_CONTROLLED to no does not change, but at this time, it is found that the virtual machine cannot access the external network. After a lot of detours, I found that after the previous settings, if there is no special need Then the above configuration can meet the demand.
For more information about CentOS, please refer to CentOS topic page http://www.linuxidc.com/topicnews.aspx?tid=14
This article permanently updates the link address: http://www.linuxidc.com/Linux/2017-10/147449.htm
Under CentOS 7, the DNS in /etc/resolv.conf was manually set. After a while, it was found to be overwritten or cleared by the system. Different from the DNS setting method under CentOS 6, there are several ways: 1. Use the brand new command line tool nmcli to set
# Show current network connection
# nmcli connection show
NAME UUID TYPE DEVICE
eno1 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 802-3-ethernet eno1
# Modify the DNS server corresponding to the current network connection, where the network connection can be identified by name or UUID
# nmcli con mod eno1 ipv4.dns "114.114.114.114 8.8.8.8"
# Take DNS configuration into effect
# nmcli con up eno1
2、 Using traditional methods, manually modify /etc/resolv.conf
[ main]
plugins=ifcfg-rh
dns=none
# systemctl restart NetworkManager.service
nameserver 114.114.114.114
nameserver 8.8.8.8
Recommended Posts