Linux系统之网卡子接口配置方法

举报
江湖有缘 发表于 2023/01/27 18:03:17 2023/01/27
【摘要】 Linux系统之网卡子接口配置方法

一、实践环境检查

1.检查系统版本

[root@jeven ~]# cat /etc/centos-release
CentOS Linux release 7.6.1810 (Core) 

2.检查系统内核版本

[root@jeven ~]# uname -r 
3.10.0-957.el7.x86_64

3.检查本地IP地址

[root@jeven ~]# ifconfig |grep -C 5 ens33
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.3.166  netmask 255.255.255.0  broadcast 192.168.3.255
        inet6 fe80::8a83:7297:7cb8:9934  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:4f:3c:68  txqueuelen 1000  (Ethernet)
        RX packets 1859420  bytes 2414510963 (2.2 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0


二、网卡子接口介绍

1.网卡子接口简介

在日常的运维工作当中,我们有时候需要在一块物理网卡上配置多个IP地址,这就是网卡子接口的概念。

2.网卡子接口的优点

打破物理网卡接口数量的限制,可以在一个接口中实现多个VLAN间的路由和通信。

3.网卡子接口的缺点

由于是多个子接口共用主接口,会让子接口性能比单个物理接口差,在网络流量过大,网络繁忙,会造成通信及网络流量瓶颈。

三 加载802.1q 模块

1.查看系统802.1q 模块信息

查看系统802.1q 模块信息

[root@jeven ~]# modinfo 8021q
filename:       /lib/modules/3.10.0-957.el7.x86_64/kernel/net/8021q/8021q.ko.xz
version:        1.8
license:        GPL
alias:          rtnl-link-vlan
retpoline:      Y
rhelversion:    7.6
srcversion:     931E6349BAB0ACE4D4A3A50
depends:        mrp,garp
intree:         Y
vermagic:       3.10.0-957.el7.x86_64 SMP mod_unload modversions 
signer:         CentOS Linux kernel signing key
sig_key:        B7:0D:CF:0D:F2:D9:B7:F2:91:59:24:82:49:FD:6F:E8:7B:78:14:27
sig_hashalgo:   sha256


2.加载802.1q 模块

modprobe 8021q           ### 加载模块

3.检查802.1q 模块加载状态

[root@jeven ~]#  lsmod | grep 8021q    
8021q                  33208  0 
garp                   14384  1 8021q
mrp                    18542  1 8021q


四、配置网卡子接口

1.设置静态IP地址

将物理网卡地址由DHCP获取,设置为静态IP地址。

  • 进入网卡配置文件目录
[root@jeven ~]# cd /etc/sysconfig/network-scripts/
[root@jeven network-scripts]# ls
ifcfg-ens33      ifdown-bnep  ifdown-ipv6  ifdown-routes    ifdown-tunnel  ifup-eth   ifup-isdn   ifup-ppp     ifup-TeamPort     network-functions
ifcfg-ens33.bak  ifdown-eth   ifdown-isdn  ifdown-sit       ifup           ifup-ib    ifup-plip   ifup-routes  ifup-tunnel       network-functions-ipv6
ifcfg-lo         ifdown-ib    ifdown-post  ifdown-Team      ifup-aliases   ifup-ippp  ifup-plusb  ifup-sit     ifup-wireless
ifdown           ifdown-ippp  ifdown-ppp   ifdown-TeamPort  ifup-bnep      ifup-ipv6  ifup-post   ifup-Team    init.ipv6-global
  • 修改物理网卡配置文件
[root@jeven network-scripts]# cat ifcfg-ens33
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
IPADDR=192.168.3.166
NETMASK=255.255.255.0
GATEWAY=192.168.3.254
DNS1=192.168.3.254
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=ba415981-963e-4130-984a-8dd764f4bb70
DEVICE=ens33
ONBOOT=yes
ZONE=public


  • 重启网卡
[root@jeven network-scripts]# service network restart 
Restarting network (via systemctl):                        [  OK  ]
[root@jeven network-scripts]# 


2.创建ens33:0配置文件

将ifcfg-ens33配置文件拷贝并改名为ifcfg-ens33:0文件

[root@jeven network-scripts]# ls
ifcfg-ens33      ifdown-bnep  ifdown-ipv6  ifdown-routes    ifdown-tunnel  ifup-eth   ifup-isdn   ifup-ppp     ifup-TeamPort     network-functions
ifcfg-ens33.bak  ifdown-eth   ifdown-isdn  ifdown-sit       ifup           ifup-ib    ifup-plip   ifup-routes  ifup-tunnel       network-functions-ipv6
ifcfg-lo         ifdown-ib    ifdown-post  ifdown-Team      ifup-aliases   ifup-ippp  ifup-plusb  ifup-sit     ifup-wireless
ifdown           ifdown-ippp  ifdown-ppp   ifdown-TeamPort  ifup-bnep      ifup-ipv6  ifup-post   ifup-Team    init.ipv6-global
[root@jeven network-scripts]# cp ifcfg-ens33 ifcfg-ens33:0
[root@jeven network-scripts]# ls
ifcfg-ens33      ifdown       ifdown-ippp  ifdown-ppp     ifdown-TeamPort  ifup-bnep  ifup-ipv6   ifup-post    ifup-Team      init.ipv6-global
ifcfg-ens33:0    ifdown-bnep  ifdown-ipv6  ifdown-routes  ifdown-tunnel    ifup-eth   ifup-isdn   ifup-ppp     ifup-TeamPort  network-functions
ifcfg-ens33.bak  ifdown-eth   ifdown-isdn  ifdown-sit     ifup             ifup-ib    ifup-plip   ifup-routes  ifup-tunnel    network-functions-ipv6
ifcfg-lo         ifdown-ib    ifdown-post  ifdown-Team    ifup-aliases     ifup-ippp  ifup-plusb  ifup-sit     ifup-wireless
[root@jeven network-scripts]# 


3.修改ens33:0文件

修改ifcfg-ens33:0文件,内容如下:

[root@jeven network-scripts]# cat ifcfg-ens33:0
TYPE=Ethernet
BOOTPROTO=static
IPADDR=192.168.3.33
NETMASK=255.255.255.0
GATEWAY=192.168.3.254
DNS1=192.168.3.254
DEVICE=ens33:0
ONBOOT=yes
ZONE=public

4.重启网卡

[root@jeven network-scripts]# service network restart 
Restarting network (via systemctl):                        [  OK  ]

5.查看子接口IP地址

查看子接口IP地址,可以看到网卡子接口配置已生效。

[root@jeven network-scripts]# ifconfig |grep ens33
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
[root@jeven network-scripts]# ifconfig |grep -C 5 ens33
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.3.166  netmask 255.255.255.0  broadcast 192.168.3.255
        inet6 fe80::8a83:7297:7cb8:9934  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:4f:3c:68  txqueuelen 1000  (Ethernet)
        RX packets 1862362  bytes 2414734860 (2.2 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 850234  bytes 175051446 (166.9 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.3.33  netmask 255.255.255.0  broadcast 192.168.3.255
        ether 00:0c:29:4f:3c:68  txqueuelen 1000  (Ethernet)

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
[root@jeven network-scripts]# 



五、测试网卡子接口

在其他服务器ping网卡子接口的IP地址进行测试连通性。

[root@server001 ~]# ifconfig  |grep ens33
[root@server001 ~]# ifconfig  |grep eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
[root@server001 ~]# ifconfig  |grep -C 5eth0
grep: 5eth0: invalid context length argument
[root@server001 ~]# ifconfig  |grep -C5 eth0
        RX packets 294460  bytes 34353514 (32.7 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 252317  bytes 47136565 (44.9 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.3.158  netmask 255.255.255.0  broadcast 192.168.3.255
        inet6 fd58:bc95:d4fb:0:38ab:86a1:2ba0:f65d  prefixlen 64  scopeid 0x0<global>
        inet6 fe80::7b2d:77fb:1708:7edb  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:a7:02:31  txqueuelen 1000  (Ethernet)
        RX packets 3760871  bytes 600897760 (573.0 MiB)
[root@server001 ~]# ping 192.168.3.33 -c 12
PING 192.168.3.33 (192.168.3.33) 56(84) bytes of data.
64 bytes from 192.168.3.33: icmp_seq=1 ttl=64 time=108 ms
64 bytes from 192.168.3.33: icmp_seq=2 ttl=64 time=2.91 ms
64 bytes from 192.168.3.33: icmp_seq=3 ttl=64 time=2.64 ms
64 bytes from 192.168.3.33: icmp_seq=4 ttl=64 time=2.72 ms
64 bytes from 192.168.3.33: icmp_seq=5 ttl=64 time=2.94 ms
64 bytes from 192.168.3.33: icmp_seq=6 ttl=64 time=2.93 ms
64 bytes from 192.168.3.33: icmp_seq=7 ttl=64 time=2.85 ms
64 bytes from 192.168.3.33: icmp_seq=8 ttl=64 time=2.91 ms
64 bytes from 192.168.3.33: icmp_seq=9 ttl=64 time=2.86 ms
64 bytes from 192.168.3.33: icmp_seq=10 ttl=64 time=3.20 ms
64 bytes from 192.168.3.33: icmp_seq=11 ttl=64 time=3.12 ms
64 bytes from 192.168.3.33: icmp_seq=12 ttl=64 time=3.15 ms

--- 192.168.3.33 ping statistics ---
12 packets transmitted, 12 received, 0% packet loss, time 11016ms
rtt min/avg/max/mdev = 2.647/11.756/108.788/29.256 ms



```


















【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。