centos 7修改ip为静态ip

首先在命令行中进行如下操作: 

sudo mv /etc/sysconfig/network-scripts/ifcfg-enp**s0f0 /etc/sysconfig/network-scripts/ifcfg-eth0
sudo vim /etc/sysconfig/network-scripts/ifcfg-eth0

hwaddr的码是通过ifconfig -a进行查看的,我的相应ip信息如下(eth0 ether后面的码就是我们要用的HWADDR):

eth0: flags=4163  mtu 1500
        inet 172.18.13.17  netmask 255.255.0.0  broadcast 172.18.255.255
        inet6 fe80::ae1f:6bff:feb3:181c  prefixlen 64  scopeid 0x20
        ether ac:1f:6b:b3:18:1c  txqueuelen 1000  (Ethernet)
        RX packets 24123  bytes 1483243 (1.4 MiB)
        RX errors 0  dropped 0  overruns 0  frame 12
        TX packets 423  bytes 49940 (48.7 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:60:28:c0  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

在ifcfg-eth0中进行如下修改:

TYPE=Ethernet
BOOTPROTO=static
ONBOOT=yes
HWADDR=ac:1f:6b:b3:18:1c
IPADDR=172.18.13.17
NETMASK=255.255.0.0
GATEWAY=172.18.0.254
DNS1=8.8.8.8
DNS2=114.114.114.114
#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=eth0
#UUID=ba50c03e-b6c4-4eb5-bb32-8c87492fd0a1
DEVICE=eth0

ONBOOT表示的是自动进行联网

IPADDR表示我设置的IP地址

BOOTPROTO=static表示设置的ip地址为静态地址

最后执行网络restart就可以了

 systemctl restart network

 

你可能感兴趣的:(网络)