Configure static IP under CentOS 7

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:

note####

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

How to set the DNS server under CentOS 7

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

Configure static IP under CentOS 7
Set static IP under Centos
Ubuntu18.04, Centos7 static IP
Configure lamp under centos6.8
Centos7 configure IP address
Centos configure multiple virtual IP
Centos configure multiple virtual IP
Install and configure keepalived under CentOS 5.9
Configure iSCSI network storage under CentOS 7.x
CentOS7 configure static address, turn off firewall
Set static IP for CentOS in VMware
Centos7 configure JDK
Summary of CentOS method to set static IP
Explain the implementation of Centos8 static IP configuration
Deploy GitBook under CentOS7
Compile Hadoop-2.7.6 under CentOS7.4
Configure Ocserv on CentOS 6
Install mysql5.7 under CentOS7
Install ActiveMQ under Centos7
Install PostgreSQL12 under CentOS7
Install CentOS under VMware
ubuntu 14.04 configure 3-wire 3IP
Deploy JDK+Tomcat8 under CentOS
Install mysql under Centos 7
Install Jenkins under Centos 7
Redis3 installation under Centos7
Install MariaDB under MariaDB Centos7
Install mysql5.1 under CentOS6.5
Centos7 configure nodejs environment
ubuntu16.04 set static ip
Configure CentOS7 GPU environment
Install PHP in yum under CentOS, configure php-fpm service
Centos: add an IP address
Xen virtualization combat under CentOS 6.6
[CentOS environment deployment] Java7/Java8 deployment under CentOS
Build OpenV** Server under CentOS7
Build OpenLDAP server under CentOS7
Redis cluster installation under CentOS
ubuntu 18.04 set static ip method
Install Oracle11gR2 database under CentOS6.9
3 partitioning tools under CentOS Linux
Install MySQL under Linux (CentOS 7)
Redis cluster installation under CentOS
Centos6.5 install and configure mongodb
Root password cracking under CentOS 7
Configure swap space on CentOS7
SELinux security settings under CentOS
Install Java JDK8 under CentOS6
Install MongoDB database under CentOS7
CentOS 6.8 under linux install mongodb
Install Mesos tutorial under CentOS7
CentOS 7 configure Java language development environment
Use Nginx and u under CentOS
Configure rsyslog log client on CentOS
CentOS 6/7 configure sendEmail to send mail
[Introduction to redis] Install redis under Centos
RabbitMQ cluster deployment record under Centos6.9
CentOS 7 configure Ruby language development environment
Installation under centos6.9 of jenkins learning
CentOS 7 configure php language development environment
Build a PXC cluster under CentOS8