centos7 设置静态IP

centos7 设置静态IP

一、查找配置文件(/etc/sysconfig/network-scripts)

[root@bogon network-scripts]# ll
总用量 232
-rw-r--r--. 1 root root   366 6月   7 10:39 ifcfg-eth0
-rw-r--r--. 1 root root   254 1月   3 00:29 ifcfg-lo
lrwxrwxrwx. 1 root root    24 6月   7 10:17 ifdown -> ../../../usr/sbin/ifdown
-rwxr-xr-x. 1 root root   654 1月   3 00:29 ifdown-bnep
-rwxr-xr-x. 1 root root  6569 1月   3 00:29 ifdown-eth
-rwxr-xr-x. 1 root root   781 1月   3 00:29 ifdown-ippp
-rwxr-xr-x. 1 root root  4540 1月   3 00:29 ifdown-ipv6
lrwxrwxrwx. 1 root root    11 6月   7 10:17 ifdown-isdn -> ifdown-ippp
-rwxr-xr-x. 1 root root  2102 1月   3 00:29 ifdown-post
-rwxr-xr-x. 1 root root  1068 1月   3 00:29 ifdown-ppp
-rwxr-xr-x. 1 root root   870 1月   3 00:29 ifdown-routes
-rwxr-xr-x. 1 root root  1456 1月   3 00:29 ifdown-sit
-rwxr-xr-x. 1 root root  1621 3月  18 2017 ifdown-Team
-rwxr-xr-x. 1 root root  1556 3月  18 2017 ifdown-TeamPort
-rwxr-xr-x. 1 root root  1462 1月   3 00:29 ifdown-tunnel
lrwxrwxrwx. 1 root root    22 6月   7 10:17 ifup -> ../../../usr/sbin/ifup
-rwxr-xr-x. 1 root root 12415 1月   3 00:29 ifup-aliases
-rwxr-xr-x. 1 root root   910 1月   3 00:29 ifup-bnep
-rwxr-xr-x. 1 root root 13442 1月   3 00:29 ifup-eth
-rwxr-xr-x. 1 root root 12075 1月   3 00:29 ifup-ippp
-rwxr-xr-x. 1 root root 11893 1月   3 00:29 ifup-ipv6
lrwxrwxrwx. 1 root root     9 6月   7 10:17 ifup-isdn -> ifup-ippp
-rwxr-xr-x. 1 root root   650 1月   3 00:29 ifup-plip
-rwxr-xr-x. 1 root root  1064 1月   3 00:29 ifup-plusb
-rwxr-xr-x. 1 root root  4981 1月   3 00:29 ifup-post
-rwxr-xr-x. 1 root root  4154 1月   3 00:29 ifup-ppp
-rwxr-xr-x. 1 root root  2001 1月   3 00:29 ifup-routes
-rwxr-xr-x. 1 root root  3303 1月   3 00:29 ifup-sit
-rwxr-xr-x. 1 root root  1755 3月  18 2017 ifup-Team
-rwxr-xr-x. 1 root root  1876 3月  18 2017 ifup-TeamPort
-rwxr-xr-x. 1 root root  2711 1月   3 00:29 ifup-tunnel
-rwxr-xr-x. 1 root root  1836 1月   3 00:29 ifup-wireless
-rwxr-xr-x. 1 root root  5419 1月   3 00:29 init.ipv6-global
-rw-r--r--. 1 root root 19948 1月   3 00:29 network-functions
-rw-r--r--. 1 root root 31027 1月   3 00:29 network-functions-ipv6
二、备份网卡文件
[root@bogon network-scripts]# cp ifcfg-eth0 ifcfg-eth0.bak
三、修改配置文件为静态ip
[root@bogon network-scripts]# vi ifcfg-eth0
修改后内容如下:
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
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=eth0
UUID=a81aa960-d8db-40f3-8a3a-c430b1984c80
DEVICE=eth0
ONBOOT=yes
IPADDR=10.211.55.10
NETMASK=255.255.255.0
NETWORK=10.211.55.1
DNS1=10.211.55.1
四、修改网关配置文件(/etc/sysconfig/network)
[root@bogon sysconfig]# vi network
内容如下:
# Created by anaconda
NETWORKING=yes
NETWORKING_IPV6=no
GATEWAY=10.211.55.1
五、重启网卡
[root@bogon sysconfig]# systemctl restart network
六、查看ip
[root@bogon sysconfig]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> 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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:1c:42:3f:bb:6f brd ff:ff:ff:ff:ff:ff
    inet 10.211.55.10/24 brd 10.211.55.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fdb2:2c26:f4e4:0:21c:42ff:fe3f:bb6f/64 scope global mngtmpaddr dynamic
       valid_lft 2591594sec preferred_lft 604394sec
    inet6 fe80::21c:42ff:fe3f:bb6f/64 scope link
       valid_lft forever preferred_lft forever
七、查看路由
[root@bogon sysconfig]# ip route
default via 10.211.55.1 dev eth0 proto static metric 100
10.211.55.0/24 dev eth0 proto kernel scope link src 10.211.55.10 metric 100
注意事项
刚装完机器不知道我的ip和网关模式为多少?
1.设置网卡
BOOTPROTO=dhcp
ONBOOT=yes
2.重启后执行第七步查看路由命令,即可知道当前的ip地址和默认的网关地址。

猜你喜欢

转载自www.cnblogs.com/xuezhigu/p/9149594.html