Centos7 下静态IP设置

Centos7 下静态IP设置

1、进入network-scripts目录并且查看该目录下存在的ifcfg-xx文件

cd /etc/sysconfig/network-scripts
#xx为用户自己目录下的ifcfg-xx 文件
vim /etc/sysconfig/network-scripts/ifcfg-xx 

2.修改如下配置内容

BOOTPROTO=static #将dncp改为static
ONBOOT="yes"  #开机时启用本配置
IPADDR=192.168.13.131 #静态ip
GATEWAY=192.168.13.2 #默认网关
NETMASK=255.255.255.0#子网掩码
DNS1=192.168.13.2 #DNS配置

3.修改后ifcfg-ens33 文件内容如下

TYPE="Ethernet"
DEFROUTE=yes
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="c40937f7-ebf8-41e8-8541-d79fc3dff61e"
DEVICE="ens33"
PREFIX=24
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
BOOTPROTO=static #将dncp改为static
ONBOOT="yes" #开机时启用本配置
DNS1=192.168.13.2 #DNS配置
IPADDR=192.168.13.131 #静态ip
NETMASK=255.255.255.0#子网掩码
GATEWAY=192.168.13.2 #默认网关

4.重启网络服务

service network restart

5.查看改动后的效果,使用ifconfig或者ip addr

 ifconfig
 #输出结果如下
 ens33: flags=4163  mtu 1500
        inet 192.168.13.131  netmask 255.255.255.0  broadcast 192.168.13.255
        inet6 fe80::c43e:1e6b:69b:5ba8  prefixlen 64  scopeid 0x20
        ether 00:0c:29:9e:22:eb  txqueuelen 1000  (Ethernet)
        RX packets 6763  bytes 520694 (508.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2700  bytes 541708 (529.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 1  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:96:18:0e  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ip addr

#输出如下
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    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: ens33:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:9e:22:eb brd ff:ff:ff:ff:ff:ff
    inet 192.168.13.131/24 brd 192.168.13.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::c43e:1e6b:69b:5ba8/64 scope link 
       valid_lft forever preferred_lft forever
3: virbr0:  mtu 1500 qdisc noqueue state DOWN qlen 1000
    link/ether 52:54:00:96:18:0e 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:  mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 1000
    link/ether 52:54:00:96:18:0e brd ff:ff:ff:ff:ff:ff

你可能感兴趣的:(Centos7 下静态IP设置)