Centos 7 : NIC NetworkManager & How to change NIC name

1

•ip addr show 中显示的IP才是有效的。
•ip addr add能在线添加IP,立即生效,但重启即丢。
•ip addr del 能在线删除IP,立即生效,但重启即丢。

2

•子连接(ifcfg-*:n)已经无效了。

3
/etc/udev/rules.d/70-persistent-net.rules 文件没有了,新添加的网卡NetworkManager自动识别。
[root@centos7 ~]# nmcli con show
NAME UUID TYPE DEVICE
Wired connection 1 0c451785-b098-4c5c-994d-9107171b439d 802-3-ethernet enp0s8
enp0s3 295e1841-0ff3-4db9-8800-4e25fc2944da 802-3-ethernet enp0s3

“Wired connection 1”是新增的网络连接,对应的网络接口叫enp0s8;
“enp0s3”是最初的网络连接,认与网络接口同名。

4
CentOS 7缺省用NetworkManager服务管理网络,而不是子连接(ifcfg-*:n)
5

网络接口统计信息

[root@centos7 ~]# ip -s link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNowN mode DEFAULT
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
RX: bytes packets errors dropped overrun mcast
0 0 0 0 0 0
TX: bytes packets errors dropped carrier collsns
0 0 0 0 0 0
2: enp0s3: <broADCAST,MULTICAST,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 08:00:27:15:35:d2 brd ff:ff:ff:ff:ff:ff
RX: bytes packets errors dropped overrun mcast
8135366 131454 0 0 0 456
TX: bytes packets errors dropped carrier collsns
646297 2441 0 0 0 0


6、ip route显示和设定路由

显示路由表

[root@centos7 ~]# ip route
default via 192.168.150.254 dev enp0s3 proto static metric 1024
192.168.150.0/24 dev enp0s3 proto kernel scope link src 192.168.150.110

太难看了,格式化一下(显示的是认网关和局域网路由,两行的内容没有共通性):

[root@centos7 tmp]# ip route|column -t
default via 192.168.150.254 dev enp0s3 proto static metric 1024
192.168.150.0/24 dev enp0s3 proto kernel scope link src 192.168.150.110


添加静态路由

[root@centos7 ~]# ip route add 10.15.150.0/24 via 192.168.150.253 dev enp0s3
[root@centos7 ~]#
[root@centos7 ~]# ip route|column -t
default via 192.168.150.254 dev enp0s3 proto static metric 1024
10.15.150.0/24 via 192.168.150.253 dev enp0s3 proto static metric 1
192.168.150.0/24 dev enp0s3 proto kernel scope link src 192.168.150.110
[root@centos7 ~]#
[root@centos7 ~]# ping 10.15.150.1
PING 10.15.150.1 (10.15.150.1) 56(84) bytes of data.
64 bytes from 10.15.150.1: icmp_seq=1 ttl=63 time=1.77 ms
64 bytes from 10.15.150.1: icmp_seq=1 ttl=63 time=1.08 ms
64 bytes from 10.15.150.1: icmp_seq=1 ttl=63 time=1.57 ms
^C


删除静态路由只需要把 add 替换成 del,或者更简单的只写目标网络

[root@centos7 ~]# ip route del 10.15.150.0/24
[root@centos7 ~]#

但是,ip route 指令对路由的修改不能保存,重启就没了。

7 FIXME

设置永久的静态路由的方法RHEL官网文档讲了几种,试验成功的只有一种:

[root@centos7 ~]#echo "10.15.150.0/24 via 192.168.150.253 dev enp0s3" > /etc/sysconfig/network-scripts/route-enp0s3

重启计算机,或者禁用再启用设备enp0s3才能生效,
注意:/etc/sysconfig/static-routes,/etc/sysconfig/network 配置文件都不好用。

8、用 ip neighbor 代替 arp -n

[root@centos7 ~]# ip nei
192.168.150.254 dev enp0s3 lladdr b8:a3:86:37:bd:f8 STALE
192.168.150.100 dev enp0s3 lladdr 90:b1:1c:94:a1:20 DELAY
192.168.150.253 dev enp0s3 lladdr 00:09:0f:85:86:b9 STALE


9、用ss 代替 netstat
对应netstat -ant

[root@centos7 ~]# ss -ant
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 *:22 *:*
ESTAB 0 0 192.168.150.110:22 192.168.150.100:53233
LISTEN 0 100 ::1:25 :::*
LISTEN 0 128 :::22 :::*

对应netstat -antp

[root@centos7 tmp]# ss -antp
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 100 127.0.0.1:25 *:*
users:(("master",1817,13))
LISTEN 0 128 *:22 *:*
users:(("sshd",1288,3))
ESTAB 0 0 192.168.150.110:22 192.168.150.100:59413
users:(("sshd",2299,3))
LISTEN 0 100 ::1:25 :::*
users:(("master",14))
LISTEN 0 128 :::22 :::*
users:(("sshd",4))
[root@centos7 tmp]#

看着真的很别扭,不管多宽的终端屏,users:部分都会折到下一行,其实是在一行的。

格式化一下,内容整齐了,但是标题行串了:

[root@centos7 tmp]# ss -antp|column -t
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 100 127.0.0.1:25 *:* users:(("master",13))
LISTEN 0 128 *:22 *:* users:(("sshd",3))
ESTAB 0 0 192.168.150.110:22 192.168.150.100:59413 users:(("sshd",3))
LISTEN 0 100 ::1:25 :::* users:(("master",14))
LISTEN 0 128 :::22 :::* users:(("sshd",4))

10、旧的network脚本和ifcfg文件
Centos7 开始,网络由 NetworkManager 服务负责管理,相对于旧的 /etc/init.d/network 脚本,NetworkManager是动态的、事件驱动的网络管理服务。旧的 /etc/init.d/network 以及 ifup,ifdown 等依然存在,但是处于备用状态,即:NetworkManager运行时,多数情况下这些脚本会调用NetworkManager去完成网络配置任务;NetworkManager么有运行时,这些脚本就按照老传统管理网络。

[root@centos7 ~]# /etc/init.d/network start
Starting network (via systemctl): [ OK ]

注意(via systemctl)。

11、网络配置文件:
/etc/sysconfig/network 说是全局设置,认里面啥也没有
/etc/hostname 用nmtui修改hostname后,主机名保存在这里
/etc/resolv.conf 保存DNS设置,不需要手工改,nmtui里面设置的DNS会出现在这里
/etc/sysconfig/network-scripts/ 连接配置信息 ifcfg 文件
/etc/NetworkManager/system-connections/ VPN、移动宽带、PPPoE连接

12

You can rename the device using the ip command: (disappear when rebooted)

ip link set eth1 down
ip link set eth1 name eth123
ip link set eth123 up


You may also want to make sure that you configure a udev rule,so that this will work on the next reboot too. The path for udev moved in CentOS 7 to /usr/lib/udev/rules.d/60-net.rules but you are still able to manage it the same way. If you added "net.ifnames=0 biosdevname=0" to your kernel boot string to return to the old naming scheme for your nics,you can remove

ACTION=="add",SUBSYstem=="net",DRIVERS=="?*",ATTR{type}=="1",PROGRAM="/lib/udev/rename_device",RESULT=="?*",NAME="$result"

And replace it with

ACTION=="add",ATTR{address}=="00:50:56:8e:3f:a7",NAME="eth123"

You need one entry per nic. Be sure to use the correct MAC address and update the NAME field. If you did not use "net.ifnames=0 biosdevname=0",be careful as there Could be unintended consequences.

12里提供的方法不能很好的应对新增加网卡的情况。

我提供的一个办法不需要改grub,也不需要改动命令方法,但也有12的问题。

这个方法不需要12方法,需要在centos7上启动一个服务,这个服务在udev服务后,或者在启动后运行,其脚本是一次性的,即上面的ip link改名脚本。


REF:

1 http://blog.csdn.net/kunatnet/article/details/45149543

2 http://www.linuxidc.com/Linux/2014-09/107375p6.htm

3 http://unix.stackexchange.com/questions/205010/centos-7-rename-network-interface-without-rebooting

相关文章

Centos下搭建性能监控Spotlight
CentOS 6.3下Strongswan搭建IPSec VPN
在CentOS6.5上安装Skype与QQ
阿里云基于centos6.5主机VPN配置
CentOS 6.3下配置multipah
CentOS安装、配置APR和tomcat-native