CentOS配置vlan

文章详细介绍了在RedHatEnterpriseLinux7环境下,如何通过加载8021q模块、修改配置文件以及使用命令行工具iplink来创建、查看和删除802.1QVLAN接口,以实现网络隔离和管理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

通过配置文件配置vlan

加载8021q模块

[root@ct7_node02 network-scripts]# modprobe 8021q
[root@ct7_node02 network-scripts]# lsmod | grep 802
8021q                  33080  0 
garp                   14384  1 8021q
mrp                    18542  1 8021q

修改配置文件

[root@ct7_node02 network-scripts]# cat ifcfg-eth3
DEVICE=eth3
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes

[root@ct7_node02 network-scripts]# cat ifcfg-eth3.220 
DEVICE=eth3.220
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.168.4.220
PREFIX=24
NETWORK=192.168.4.254
VLAN=yes

重启网络服务

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

验证

[root@ct7_node02 network-scripts]# ip a
...
5: eth3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 74:52:01:01:02:04 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::7652:1ff:fe01:204/64 scope link 
       valid_lft forever preferred_lft forever
...
10: eth3.220@eth3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
    link/ether 74:52:01:01:02:04 brd ff:ff:ff:ff:ff:ff
    inet 192.168.4.220/24 brd 192.168.4.255 scope global eth3.220
       valid_lft forever preferred_lft forever
    inet6 fe80::7652:1ff:fe01:204/64 scope link 
       valid_lft forever preferred_lft forever

[root@ct7_node02 network-scripts]# ip -d link show eth3.220
10: eth3.220@eth3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT qlen 1000
    link/ether 74:52:01:01:02:04 brd ff:ff:ff:ff:ff:ff promiscuity 0 
    vlan protocol 802.1Q id 220 <REORDER_HDR> addrgenmode eui64 

通过命令行配置vlan

要在以太网接口 eth02中创建名为 VLAN8、ID 为 8 的 802.1Q VLAN 接口,请作为 root 运行以下命令:

[root@ct7_node02 network-scripts]# ip link add link eth0 name eth0.8 type vlan id 8

查看vlan

命令:ip -d link show eth0.8

[root@ct7_node02 network-scripts]# ip -d link show eth0.8
11: eth0.8@eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000
    link/ether 74:52:01:01:02:01 brd ff:ff:ff:ff:ff:ff promiscuity 0 
    vlan protocol 802.1Q id 8 <REORDER_HDR> addrgenmode eui64 
[root@ct7_node02 network-scripts]# ip a
...
11: eth0.8@eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
    link/ether 74:52:01:01:02:01 brd ff:ff:ff:ff:ff:ff

移除 VLAN

[root@ct7_node02 network-scripts]# ip link delete eth0.8

红帽参考连接

https://access.redhat.com/documentation/zh-cn/red_hat_enterprise_linux/7/html/networking_guide/sec-configure_802_1q_vlan_tagging_using_the_command_line

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值