美文网首页
linux修改IP为静态IP

linux修改IP为静态IP

作者: Fa1se003 | 来源:发表于2016-05-30 23:10 被阅读503次

系统版本 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

相关文章

网友评论

      本文标题:linux修改IP为静态IP

      本文链接:https://www.haomeiwen.com/subject/exscdttx.html