linux设置ip的vlan,使用IP和vconfig配置vlan子接口

一、使用IP命令配置

此前 Arch Linux 用 vconfig 命令设置 VLANs ,该命令已被 ip 命令取代。下面的范例假定 网口 是 enp125s0f0,名字 是 enp125s0f0.100 ,vlan id 是 100。

1. 创建 VLAN 设备

用下列命令添加 VLAN 网口:# ip link add link enp125s0f0 name enp125s0f0.100 type vlan id 100

执行 ip link 命令确认 VLAN 已创建。

这个 VLAN 网口就像一个普通的物理网口,所有流经这个网口的数据包将被加上 VLAN tag 并流经它关联的物理网口(本例中的 enp125s0f0)。仅配置为相同 VLAN 的设备可接收这些数据包,否则将被丢弃。

Using a name like enp125s0f0.100 is just convention and not enforced; you can alternatively use enp125s0f0_100 or something descriptive like IPTV. To see the VLAN ID on an interface, in case you used an unconventional name:# ip -d link show enp125s0f0.100

The -d flag shows full details on an interface:# ip -d link show enp125s0f0.100

7: enp125s0f0.100@enp125s0f0: mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000

link/ether 8c:e5:ef:97:50:c8 brd ff:ff:ff:ff:ff:ff promiscuity 0 minmtu 0 maxmtu 65535

vlan protocol 802.1Q id 100 addrgenmode eui64 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535

2. 添加 IP

Now add an IPv4 address to the just created vlan link, and activate the link:# ip addr add 192.168.100.1/24 brd 192.168.100.255 dev

enp125s0f0.100

# ip link set dev

enp125s0f0.100

up

3. 关闭设备

To cleanly shutdown the setting before you remove the link, you can do:# ip link set dev

enp125s0f0.100

down

4. 移除设备

Removing a VLAN interface is significantly less convoluted# ip link delete enp125s0f0.100

二、使用vconfig配置

1.安装vlan(vconfig)和加载8021q模块#aptitude install vlan

#modprobe 8021q

或:

#yum install vconfig

#modprobe 8021q

#lsmod |grep -i 8021q

2.使用linux vconfig命令配置vlan#vconfig add enp8s0f1 100

#vconfig add enp8s0f1 200

在enp8s0f1接口上配置两个VLAN#vconfig set_flag enp8s0f1.100 1 1

#vconfig set_flag enp8s0f1.200 1 1

设置VLAN的REORDER_HDR参数,默认就行了。可以使用cat /proc/net/vlan/enp8s0f1.100查看enp8s0f1.100参数

配置网络信息#ifconfig enp8s0f1 0.0.0.0

#ifconfig enp8s0f1.100 192.168.100.50 netmask 255.255.255.0 up

#ifconfig enp8s0f1.200 192.168.200.50 netmask 255.255.255.0 up

删除VLAN命令#vconfig rem enp8s0f1.100

#vconfig rem enp8s0f1.200

3.将VLAN信息写入配置文件#echo "modprobe 8021q">>/etc/rc.local

开机加载8021q模块,或者使用echo"8021q">>/etc/modules

#cp /etc/network/interfaces /etc/network/interfaces.default

#vim /etc/network/interfaces

auto lo enp8s0f1

iface lo inet loopback

iface enp8s0f1.100 inet static

address 192.168.100.50

netmask 255.255.255.0

iface enp8s0f1.200 inet static

address 192.168.200.50

netmask 255.255.255.0

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值