跳转至

CentOS 7 配置网络


2016-07-18 by dongnan

配置文件

centos 7.xcentos 6.x 的网络配置项基本相同,需要注意的是 NM_CONTROLLED=no选项,表示该接口将通过该配置文件进行设置,而不是通过网络管理器进行管理。

示例配置

# 执行命令
vim /etc/sysconfig/network-scripts/ifcfg-eth1

# 内容类似如下
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=eth1
DEVICE=eth1
ONBOOT=yes
DNS1=202.106.0.20
DNS2=202.106.45.151
IPADDR=10.0.0.20
PREFIX=24
GATEWAY=10.0.0.1
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes

重启网络

systemctl restart network.service

验证

# 执行命令
ip add show eth1

3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 06:bc:f5:28:f4:db brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.20/24 brd 10.0.0.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::4bc:f5ff:fe28:f4db/64 scope link
       valid_lft forever preferred_lft forever

扩展:网络管理器

nmcli dev status

DEVICE       TYPE      STATE      CONNECTION
docker0      bridge    connected  docker0    
eth0         ethernet  connected eth0      
veth9f2311a  ethernet  unmanaged  --        
vethf764244  ethernet  unmanaged  --        
lo           loopback  unmanaged  --

帮助

# 执行命令
nmcli dev status

NAME
       nmcli - command‐line tool for controlling NetworkManager

SYNOPSIS
       nmcli  [ OPTIONS ] OBJECT { COMMAND | help }

       OBJECT := { general | networking | radio | connection | device | agent  }

       OPTIONS := {
       -t[erse]
       -p[retty]
       -m[mode] tabular | multiline
       -f[ields] <field1,field2,...> | all | common
       -e[scape] yes | no
       -n[ocheck]
       -a[sk]
       -w[ait] <seconds>
       -v[ersion]
       -h[elp]
       }

参考

如何为CentOS 7配置静态IP地址

回到页面顶部