centos7 修改静态ip

修改linux系统的静态IP

修改步骤 : 

1)执行ip add 命令 下面的ens33才是真实IP

[root@localhost ~]# ip add 
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    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 group default qlen 1000
    link/ether 00:0c:29:e8:76:84 brd ff:ff:ff:ff:ff:ff
    inet 192.168.109.145/24 brd 192.168.109.255 scope global noprefixroute dynamic ens33
       valid_lft 1188sec preferred_lft 1188sec
    inet6 fe80::2839:870b:b85b:c218/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

2)修改ens33这个网卡的配置

[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# vi ifcfg-ens33

原来的内容是这样的 : 

TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="dhcp"
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="45741c09-63f3-44ad-b4f9-6bcdd2e5d4f0"
DEVICE="ens33"
ONBOOT="yes"

修改如下 : 

TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"     #修改为static
IPADDR="192.168.109.151" #IP
NETMASK="255.255.255.0" #子网掩码
GATEWAY="192.168.109.2" #网关
DNS="192.168.92.2"    #DNS
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="45741c09-63f3-44ad-b4f9-6bcdd2e5d4f0"
DEVICE="ens33"
ONBOOT="yes"

3)停止 networkManager 服务 这样才能上网

[root@localhost network-scripts]# systemctl stop NetworkManager.service

4)关闭自动启动

[root@localhost network-scripts]# systemctl disable NetworkManager.service
Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service.

5)编辑/etc/resolv.conf 文件

[root@localhost network-scripts]# vi /etc/resolv.conf
# Generated by NetworkManager
search localdomain
nameserver 192.168.109.2 #如没有,需要手动添加 设置为网关

6)重启网络服务

[root@localhost network-scripts]# systemctl restart network.service

7)查看网卡配置

[root@localhost network-scripts]# ip add
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    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 group default qlen 1000
    link/ether 00:0c:29:e8:76:84 brd ff:ff:ff:ff:ff:ff
    inet 192.168.109.151/24 brd 192.168.109.255 scope global ens33 #修改之后
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fee8:7684/64 scope link 
       valid_lft forever preferred_lft forever

8)验证是否可以正常上网

[root@localhost network-scripts]# ping www.baidu.com
PING www.a.shifen.com (119.75.217.109) 56(84) bytes of data.
64 bytes from 119.75.217.109 (119.75.217.109): icmp_seq=1 ttl=128 time=5.59 ms
64 bytes from 119.75.217.109 (119.75.217.109): icmp_seq=2 ttl=128 time=7.22 ms
64 bytes from 119.75.217.109 (119.75.217.109): icmp_seq=3 ttl=128 time=5.44 ms

 

 

 

 

你可能感兴趣的:(centos)