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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux系统之网卡子接口配置方法相关的知识,希望对你有一定的参考价值。

(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.网卡子接口简介

2.网卡子接口的优点

3.网卡子接口的缺点

三 加载802.1q 模块

1.查看系统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地址

  • 进入网卡配置文件目录
[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配置文件

[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文件

[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地址

[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]# 



五、测试网卡子接口

[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



```


















以上是关于Linux系统之网卡子接口配置方法的主要内容,如果未能解决你的问题,请参考以下文章

Linux网络管理之网卡别名及网卡绑定配置

网络配置网卡子接口

Linux系统之Bonding 网卡绑定配置方法

Linux(CentOS)之网络配置

linux命令之网络管理命令(上)

linux网络配置之bond-team-bridge