Centos 7 配置静态ip方法

ip管理主文件存放于/etc/sysconfig/network-scripts/目录

查看文件夹文件:

# ls /etc/sysconfig/network-scripts/
ifcfg-eno1  ifdown-bnep  ifdown-ippp  ifdown-post    ifdown-sit       ifdown-tunnel  ifup-bnep  ifup-ippp  ifup-plip   ifup-ppp     ifup-Team      ifup-wireless      network-functions-ipv6
ifcfg-lo    ifdown-eth   ifdown-ipv6  ifdown-ppp     ifdown-Team      ifup           ifup-eth   ifup-ipv6  ifup-plusb  ifup-routes  ifup-TeamPort  init.ipv6-global
ifdown      ifdown-ib    ifdown-isdn  ifdown-routes  ifdown-TeamPort  ifup-aliases   ifup-ib    ifup-isdn  ifup-post   ifup-sit     ifup-tunnel    network-functions

CentOS默认使用第一个文件ifcfg-eno1 作为主配置;#每个机器可能不同,以显示为准

查看eno1配置:

# cat /etc/sysconfig/network-scripts/ifcfg-eno1 
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=eno1
UUID=ea4bbbab-1804-46df-b8f9-1451e5a710fc
DEVICE=eno1
ONBOOT=no

主要修改标识如下

vi /etc/sysconfig/network-scripts/ifcfg-eno1

使用 i 进入INSERT操作进而编辑

TYPE=Ethernet
BOOTPROTO=static
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=eno1
UUID=ea4bbbab-1804-46df-b8f9-1451e5a710fc
DEVICE=eno1
ONBOOT=yes
IPADDR=192.168.1.45
GATEWAY=192.168.1.1
NETMASK=255.255.255.0
DNS1=192.168.1.1

修改如下内容:

BOOTPROTO=static                  #使用static配置
ONBOOT=yes                        #开机启用本配置
IPADDR=192.168.1.45               #静态IP
GATEWAY=192.168.1.1               #默认网关
NETMASK=255.255.255.0             #子网掩码
DNS1=192.168.1.1                  #DNS配置

重启网络服务

systemctl restart network.service

查看静态IP

1: lo: mtu 65536 qdisc noqueue state UNKNOWN 
    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: eno1: mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 6c:0b:84:3c:70:ef brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.45/24 brd 192.168.1.255 scope global eno1
       valid_lft forever preferred_lft forever
    inet6 fe80::6e0b:84ff:fe3c:70ef/64 scope link 
       valid_lft forever preferred_lft forever

最后台可以ping一下网络通不通,如果通了,那就没问题

最后修改:1年前
如果觉得我的文章对你有用,请随意赞赏

共有 0 条评论