Linux网络子接口配置

Linux网络子接口配置,第1张

方式一:临时方式(重启则失效):

添加网络子接口

ifconfig eth0:1 10.1.77.87 netmask 255.255.255.0

除子接口:

ifconfig eth0:1 10.1.77.87 netmask 255.255.255.0 down

注:在/etc/rc.local中配置命令可以每次重启PC时均执行次命令配置子网络

方式二:

修改配置文件,永久生效

可以使用hybrid来实现。下面是我的配置,给你参考一下。其中513为打tag;515不打tag

interface GigabitEthernet0/5

stp edged-port enable

port link-type hybrid

port hybrid vlan 513 tagged

port hybrid vlan 515 untagged

port hybrid pvid vlan 515

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

用下列命令添加 VLAN 网口:

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

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

 Using a  name  like enp125s0f0.100 is just convention and not enforcedyou 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:

The -d flag shows full details on an interface:

Now add an IPv4 address to the just created vlan link, and activate the link:

To cleanly shutdown the setting before you remove the link, you can do:

Removing a VLAN interface is significantly less convoluted

在enp8s0f1接口上配置两个VLAN

设置VLAN的REORDER_HDR参数,默认就行了。

配置网络信息

删除VLAN命令

开机加载8021q模块,或者使用


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11599583.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存