一:  修改网卡配置文件(操作前先备份一下该文件),/etc/sysconfig/network-scripts/

具体操作如下:

1:进入修改目录

 [root@localhost ~]# clear   # 1: root 用户登录 并清理屏幕
[root@localhost ~]# cd /etc/sysconfig/network-scripts/ #2:进入 设置ip 信息的 /etc/sysconfig/network-scripts/ 目录下
[root@localhost network-scripts]# ls #3 查看该目录下的文件信息

ifcfg-ens33 ifdown-ipv6 ifdown-TeamPort ifup-ippp ifup-routes network-functions 5 ifcfg-lo ifdown-isdn ifdown-tunnel ifup-ipv6 ifup-sit network-functions-ipv6 6 ifdown ifdown-post ifup ifup-isdn ifup-Team 7 ifdown-bnep ifdown-ppp ifup-aliases ifup-plip ifup-TeamPort 8 ifdown-eth ifdown-routes ifup-bnep ifup-plusb ifup-tunnel 9 ifdown-ib ifdown-sit ifup-eth ifup-post ifup-wireless 10 ifdown-ippp ifdown-Team ifup-ib ifup-ppp init.ipv6-global 11

Centos7  设置静态IP地址-LMLPHP

2:查看 网卡 ifcfg-ens33  (网卡:每个机器的网卡名称都不相同)

 [root@localhost network-scripts]# cat ifcfg-ens33
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"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="59469ff2-89aa-4cb0-9304-bb1ca20c9db3"
DEVICE="ens33"
ONBOOT="yes"

3:备份 网卡 ifcfg-ens33   信息

 [root@localhost network-scripts]# cp ifcfg-ens33  ifcfg-ens33_bak_20170827
 

4:编辑 网卡网卡 ifcfg-ens33   信息

默认该文件中还有其他配置,可以都删除或注释。

 [root@localhost network-scripts]# vi  ifcfg-ens33
[root@localhost network-scripts]# cat ifcfg-ens33
TYPE="Ethernet"
BOOTPROTO="static"
IPADDR=192.168.1.21
NETMASK=255.255.255.0
NETWORK=192.168.1.1
NAME="ens33"
ME="ens33"
ONBOOT="yes"
DNS1=192.168.1.1 #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"
#IPV6_ADDR_GEN_MODE="stable-privacy"
#NAME="ens33"
#UUID="59469ff2-89aa-4cb0-9304-bb1ca20c9db3"
#DEVICE="ens33"
#ONBOOT="yes"

二:修改网关配置文件,/etc/sysconfig/network 信息 ,如下:

1:切换目录,查看文件信息

 [root@localhost network-scripts]# cd ..
[root@localhost sysconfig]# ls
atd cgred ebtables-config init iptables-config kernel man-db network-scripts pluto rdisc rsyncd saslauthd svnserve virtlogd
authconfig console fcoe ip6tables iptables.rpmnew ksm modules nfs qemu-ga readonly-root rsyslog selinux sysstat wpa_supplicant
autofs cpupower firewalld ip6tables-config irqbalance libvirtd netconsole ntpd radvd rpcbind run-parts smartmontools sysstat.ioconf
cbq crond grub iptables kdump libvirt-guests network ntpdate raid-check rpc-rquotad samba sshd virtlockd
[root@localhost sysconfig]# pwd
/etc/sysconfig
[root@localhost sysconfig]# cat network
# Created by anaconda

Centos7  设置静态IP地址-LMLPHP

2:修改 network 文件信息

 [root@localhost sysconfig]# vi  network
[root@localhost sysconfig]# cat network
# Created by anaconda NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=localhost.localdomain
GATEWAY=192.168.1.1

3:重启服务:

 [root@localhost sysconfig]# systemctl restart network
 

测试:

服务重启之后的ip信息

Centos7  设置静态IP地址-LMLPHP

原ip地址登录不了了

Centos7  设置静态IP地址-LMLPHP

注:本文参考了cnblogs:oslivan的《Centos7下面配置静态IP》文章

04-30 04:41