189 8069 5689

四、confignetwork

1、学习rhel7中新的网络配置工具和网卡命名规则

为东港等地区用户提供了全套网页设计制作服务,及东港网站建设行业解决方案。主营业务为成都网站建设、做网站、东港网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

下面这段文字参考红帽官网网络配置第8章2节,在rhel7/centos7中网卡的命名规则有些改变,增加了nmcli网络管理工具。

1、A rule in /usr/lib/udev/rules.d/60-net.rules instructs the udev helper utility, /lib/udev/rename_device, to look into all /etc/sysconfig/network-scripts/ifcfg-suffix files. If it finds an ifcfg file with a HWADDR entry matching the MAC address of an interface it renames the interface to the name given in the ifcfg file by the DEVICE directive.
2、A rule in /usr/lib/udev/rules.d/71-biosdevname.rules instructs biosdevname to rename the interface according to its naming policy, provided that it was not renamed in a previous step, biosdevname is installed, and biosdevname=0 was not given as a kernel command on the boot command line.

3、A rule in /lib/udev/rules.d/75-net-description.rules instructs udev to fill in the internal udev device property values ID_NET_NAME_ONBOARD, ID_NET_NAME_SLOT, ID_NET_NAME_PATH, ID_NET_NAME_MAC by examining the network interface device. Note, that some device properties might be undefined.

4、A rule in /usr/lib/udev/rules.d/80-net-name-slot.rules instructs udev to rename the interface, provided that it was not renamed in step 1 or 2, and the kernel parameter net.ifnames=0 was not given, according to the following priority: ID_NET_NAME_ONBOARD, ID_NET_NAME_SLOT, ID_NET_NAME_PATH. It falls through to the next in the list, if one is unset. If none of these are set, then the interface will not be renamed.

2、配置网卡使用rhel6版本的网卡配置方式:

[root@station66 ~]# cat /etc/udev/rules.d/70-persistent-net.rules 

# This file was automatically generated by the /lib/udev/write_net_rules

# program, run by the persistent-net-generator.rules rules file.

#

# You can modify it, as long as you keep each rule on a single

# line, and change only the value of the NAME= key.

# PCI device 0x8086:0x100f (e1000)

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:36:87:62", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

[root@station71 ~]# cat /etc/udev/rules.d/70-persistent-ipoib.rules 

# This is a sample udev rules file that demonstrates how to get udev to

# set the name of IPoIB interfaces to whatever you wish.  There is a

# 16 character limit on network device names though, so don't go too nuts

#

# Important items to note: ATTR{type}=="32" is IPoIB interfaces, and the

# ATTR{address} match must start with ?* and only reference the last 8

# bytes of the address or else the address might not match on any given

# start of the IPoIB stack

#

# Note: as of rhel7, udev is case sensitive on the address field match

# and all addresses need to be in lower case.

#

# ACTION=="add", SUBSYSTEM=="net", DRIVERS=="?*", ATTR{type}=="32", ATTR{address}=="?*00:02:c9:03:00:31:78:f2", NAME="mlx4_ib3

  • 编辑网卡配置文件ifcfg-eno16777736修改为ifcfg-eth0,修改DEVICE,NAME,HWADDR,NM_CONTROLLED等参数.

  • 禁用ipv6和biosdevname功能,传递这2个参数给kernel:net.ifnames=0 ipv6.disable=1,重新生成grub.cfg配置文件即可

我们来具体操作一把:

[root@station71 network-scripts]# cat /etc/sysconfig/network-scripts/ifcfg-eth0  #这块叫啥没有关系的哈!

TYPE=Ethernet

HWADDR=00:0c:29:95:b5:21

BOOTPROTO=none

NAME=eth0

DEVICE=eth0

ONBOOT=yes

IPADDR=192.168.99.71

PREFIX=24

GATEWAY=192.168.99.1

DNS1=202.106.46.151

[root@station71 ~]#vim  /etc/default/grub  +6 #给内核传递参数关闭biosdevname功能关闭ipv6.

GRUB_CMDLINE_LINUX="net.ifnames=0ipv6.disable=1rd.lvm.lv=rootvg/root rd.lvm.lv=rootvg/swap rhgb quiet"

[root@station71 ~]# grub2-mkconfig    /boot/grub2/grub.cfg 

现在重启看到我们的网卡应该是eth0了、如果改个网卡的名字都需要重启,那还搞毛线,事实上是uptime在几千的很常见。

[root@station71 network-scripts]# ifconfig  eno16777736   down 

[root@station71 network-scripts]# ethtool-i  eno16777736    #网卡的驱动名字

driver: e1000

[root@station71 network-scripts]# modinfo  e1000            #网卡的驱动程序所在的模块

filename:       /lib/modules/3.10.0-327.el7.x86_64/kernel/drivers/net/ethernet/intel/e1000/e1000.ko

[root@station71 network-scripts]# modprobe  -r  e1000        #卸载网卡驱动模块

[root@station71 network-scripts]# lsmod    |grep   e1000     #查看一下

[root@station71 network-scripts]# modprobe  e1000           #重新加载网卡驱动

3、nmcli工具使用及NetworkManager服务

需求1:

配置俩个虚拟机网络,一个桥接到物理网络的无线路由器,一个选择自定义网络配置一个192.168.99.0的网段,编辑虚拟机配置2张网卡。eno16777736用于桥接和eno33554984用于虚拟机私有网络

1、给eno16777736配置三个connection,其中两个dhcp自动获取,另外一个需手动配置ip地址信息192.168.100.77/24和gateway配置192.168.100.1域名解析地址配置为202.106.46.151

2、给eno33554984配置一个connection,需手动配置一个ip地址信息

工作一个号,家庭一个号,两不耽误!

[root@station71 ~]# nmcli  device 

DEVICE       TYPE      STATE         CONNECTION 

virbr0       bridge    connected     virbr0     

eno50332208  ethernet  connected     eth3       

eno16777736  ethernet  disconnected  --         

eno33554984  ethernet  disconnected  --         

lo           loopback  unmanaged     --         

virbr0-nic   tap       unmanaged     --         

[root@station71 ~]# nmcliconnection add type ethernet ifname eno16777736  con-name eth0

Connection 'eth0' (3d0ea27f-aee7-4598-9c23-679fde3de18f) successfully added.

[root@station71 ~]# nmcliconnection add type ethernet ifname eno16777736  con-name eth0.home

Connection 'eth0.home' (54ef6f15-7981-4f0d-9958-15d6adabb05c) successfully added.

[root@station71 ~]# nmcliconnection add type ethernet ifname eno16777736  con-name eth0.work

Connection 'eth0.work' (07d80f13-d36d-43f0-9b07-0648dd91e164) successfully added.

[root@station71 ~]# nmcliconnection modify eth0 ipv4.method manual ipv4.addresses 192.168.100.71/24 ipv4.gateway 192.168.100.1 ipv4.dns 202.106.46.151

[root@station71 ~]# nmcliconnection modify eth0.home ipv4.method auto ipv4.dns 202.106.46.151

[root@station71 ~]# nmcliconnection modify eth0.work ipv4.method auto ipv4.dns 202.106.195.68

[root@station71 ~]# nmcliconnection add type ethernet ifname eno33554984  con-name eth2

Connection 'eth2' (8a97025f-4581-410f-80bd-31b5759970de) successfully added.

[root@station71 ~]# nmcliconnection modify eth2 ipv4.method manual ipv4.addresses 192.168.99.71/24 ipv4.gateway 192.168.99.1 

[root@station71 ~]# nmcliconnection up eth0 ; nmcli  connection  up eth2

Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/31)

Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/32)

[root@station71 ~]# nmclidevice 

DEVICE       TYPE      STATE      CONNECTION 

virbr0       bridge    connected  virbr0     

eno16777736  ethernet  connected  eth0       

eno33554984  ethernet  connected  eth2       

eno50332208  ethernet  connected  eth3       

lo           loopback  unmanaged  --         

virbr0-nic   tap       unmanaged  --         

[root@station71 ~]# nmcliconnection show

NAME       UUID                                  TYPE            DEVICE      

virbr0     0d0064a4-b64e-44de-82c7-5f4eb991f1bd  bridge          virbr0      

eth2       8a97025f-4581-410f-80bd-31b5759970de  802-3-ethernet  eno33554984 

eth0.work  07d80f13-d36d-43f0-9b07-0648dd91e164  802-3-ethernet  --          

eth0.home  54ef6f15-7981-4f0d-9958-15d6adabb05c  802-3-ethernet  --          

eth0       3d0ea27f-aee7-4598-9c23-679fde3de18f  802-3-ethernet  eno16777736 

eth3       919158d0-ecfc-468a-aa99-85891161a972  802-3-ethernet  eno50332208 

[root@station71 ~]# nmcliconnection show  --active

NAME    UUID                                  TYPE            DEVICE      

virbr0  0d0064a4-b64e-44de-82c7-5f4eb991f1bd  bridge          virbr0      

eth2    8a97025f-4581-410f-80bd-31b5759970de  802-3-ethernet  eno33554984 

eth0    3d0ea27f-aee7-4598-9c23-679fde3de18f  802-3-ethernet  eno16777736 

eth3    919158d0-ecfc-468a-aa99-85891161a972  802-3-ethernet  eno50332208 

[root@station71 ~]# ping  www.baidu.com

PING www.a.shifen.com (61.135.169.125) 56(84) bytes of data.

64 bytes from 61.135.169.125: icmp_seq=1 ttl=57 time=6.31 ms

^C

--- www.a.shifen.com ping statistics ---


本文标题:四、confignetwork
网站地址:http://cdxtjz.cn/article/jdjphj.html

其他资讯