linux修改IP為靜態IP

weixin_34320159發表於2016-05-30

系統版本 rhel7.2

1、首先ifconfig看一下我們的裝置名字,我查到的是eno16777736,ip是192.168.1.7

[sam@yl 桌面]$ ifconfig
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.7  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::20c:29ff:febc:1dfe  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:bc:1d:fe  txqueuelen 1000  (Ethernet)
        RX packets 52  bytes 9322 (9.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 91  bytes 10275 (10.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 4  bytes 340 (340.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4  bytes 340 (340.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:4a:d0:88  txqueuelen 0  (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

2、修改我們的配置檔案(首先要確定有許可權,我是直接su切換到root下修改的)

[root@yl 桌面]# vim /etc/sysconfig/network-scripts/ifcfg-eno16777736
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="402edb11-e974-4fa5-95b1-1718af166586"
DEVICE="eno16777736"
ONBOOT="yes"

修改BOOTPROTO為static或者none,這倆都是指定ip為靜態的。
然後在下面新增IP、子網掩碼、閘道器、DNS

IPADDR=192.168.1.15
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=114.114.114.114

3、重啟(三種方式總有一款適合你)

1、service network restart
2、systemctl restart NetworkManager
3、先關閉再啟動
  ifdown eno16777736
  ifup eno16777736

動態獲取IP :
BOOTPROTO則改為dhcp
然後去掉IP、子網掩碼、閘道器、DNS

相關文章