Linux vlan configuration

Using Config Files

Asuming the VLAN ID is 5. You need to copy file /etc/sysconfig/network-scripts/ifcfg-eth0 to /etc/sysconfig/network-scripts/ifcfg-eth0.5

 cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0.5

Now, We have network card (eth0) and it needs to use tagged network traffic for VLAN ID 5.

 eth0 - Your regular network interface
 eth0.5 - Your virtual interface that use untagged frames

Do NOT modify /etc/sysconfig/network-scripts/ifcfg-eth0 file. Now open file /etc/sysconfig/network-scripts/ifcfg-eth0.5 using vi text editor:

 vi /etc/sysconfig/network-scripts/ifcfg-eth0.5

Find DEVICE=ifcfg-eth0line and replace with:

 DEVICE=ifcfg-eth0.5

Append line:

 VLAN=yes

Also make sure you assign correct IP address using DHCP or static IP. Save the file. Remove gateway entry from all other network config files. Only add gateway to /etc/sysconfig/network file. Save and close the file. Restart network:

 /etc/init.d/network restart

Please note that if you need to configure for VLAN ID 2 then copy the copy file /etc/sysconfig/network-scripts/ifcfg-eth0 to /etc/sysconfig/network-scripts/ifcfg-eth0.2 and do the above procedure again.

 

Using vconfig command

Above method is perfect and works with Red hat Enterprise Linux / CentOS / Fedora Linux without any problem. However, you will notice that there is a command called vconfig. The vconfig program allows you to create and remove vlan-devices on a vlan enabled kernel. Vlan-devices are virtual ethernet devices which represents the virtual lans on the physical lan.

Please note that this is yet another method of configuring VLAN. If you are happy with above method no need to read below.

Add VLAN

Add VLAN ID 5 with follwing command for eth0:

 vconfig add eth0 5

The vconfig add command creates a vlan-device on eth0 which result into eth0.5 interface. You can use normal ifconfig command to see device information:

 ifconfig eth0.5

Use ifconfig to assign IP address to vlan interfere :

 ifconfig eth0.5 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255 up

Get detailed information about VLAN interface:

 cat /proc/net/vlan/eth0.5

Delete VLAN

If you wish to delete VLAN interface delete command:

 ifconfig eth0.5 down
 vconfig rem eth0.5

Linux VLAN Configuration Issue

  • Not all network drivers support VLAN. You may need to patch your driver.
  • MTU may be another problem. It works by tagging each frame i.e. an Ethernet header extension that enlarges the header from 14 to 18 bytes. The VLAN tag contains the VLAN ID and priority. See Linux VLAN site for patches and other information.
  • Do not use VLAN ID 1 as it may be used for admin purpose.

Errors

 sudo vconfig add eth0 15
 WARNING:  Could not open /proc/net/vlan/config.  Maybe you need to load the 8021q module, or maybe you are not using PROCFS??
 Added VLAN with VID == 15 to IF -:eth0:-

Solution

 modprobe 8021q
 
VLAN HOWTO:
1. Connect the eth0 interface of your linux machine to the switch.
2. Remove the IP Address information on the eth0 interface

# ifconfig eth0 0.0.0.0
# ifconfig eth0 up

3. Configure 2 VLANs on the eth0 interface using vconfig as follows (100,200 are the VLAN id's). If the 8021q.o module is not loaded, the vconfig command (when invoked first time) will automatically load the module.

# vconfig add eth0 100
# vconfig add eth0 200

4. Configure IP on the VLAN interfaces

# ifconfig eth0.100 xxx.xxx.xxx.xxx netmask 255.255.252.0 up
# ifconfig eth0.200 yyy.yyy.yyy.yyy netmask 255.255.255.0 up

5. Preserve the vlan configuration across reboots by adding it to configuration files. Create the appropriate ifcfg files for eth0, eth0.100 and eth0.200 in /etc/sysconfig/network-scripts/

# cd /etc/sysconfig/network-scripts/

Contents of ifcfg-eth0
DEVICE=eth0
ONBOOT=no
TYPE=Ethernet

Contents of ifcfg-eth0.100
DEVICE=eth0.100
IPADDR=xxx.xxx.xxx.xxx
NETMASK=255.255.252.0
VLAN=yes
ONBOOT=yes
BOOTPROTO=none

Contents of ifcfg-eth0.200
DEVICE=eth0.200
IPADDR=yyy.yyy.yyy.yyy
NETMASK=255.255.0.0
VLAN=yes
ONBOOT=yes
BOOTPROTO=none

Update /etc/sysconfig/network file to make the GATEWAYDEV use the public vlan interface.

Contents of /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=un1xf00
GATEWAY=xxx.xxx.xxx.1
DOMAINNAME=dev.un1xf00.com
GATEWAYDEV=eth0.100


6. The VLAN configuration on the server can be verified in the file /proc/net/vlan/config. Sample contents are shown below.

VLAN Dev name | VLAN ID
Name-Type: VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD
eth0.100 | 100 | eth0
eth0.200 | 200 | eth0

More at unix linux & storage
<think>嗯,用户想了解如何在Linux中使用NMTUI配置VLAN和PPPoE。首先,我需要回忆一下NMTUI的基本用法。NMTUI是NetworkManager的文本用户界面工具,适合在终端下进行网络配置。根据引用中的内容,比如引用[2]和引用[5]提到了nmtui和nmcli,这些都是NetworkManager的一部分。 接下来,配置VLAN的话,可能需要先了解VLAN的概念,然后在NMTUI中添加新的连接,选择VLAN类型。引用[3]提到使用nmcli命令创建连接,可能NMTUI的步骤类似。需要指定父接口和VLAN ID,对吗?比如在nmcli中会用到dev和id参数,那么在NMTUI中应该也有相应的选项。 然后是PPPoE配置,PPPoE常用于宽带连接。用户需要输入账号密码,可能在NMTUI中选择PPPoE类型,填写相关信息。引用[3]和引用[4]中提到了设置IP地址、网关和DNS,但PPPoE可能不需要手动设置这些,而是自动获取。需要注意PPPoE的配置可能需要指定以太网接口作为父设备。 另外,用户可能遇到的问题包括如何激活连接,确保服务正常运行。根据引用[5],NetworkManager服务需要运行,所以可能需要检查服务状态。还有,配置完成后可能需要重启连接或使用nmcli connection up来激活,如引用[4]中的例子。 需要注意,引用中的资料提到的是基本网络配置,但VLAN和PPPoE可能需要特定的步骤。需要确保步骤清晰,比如在NMTUI中选择正确的连接类型,输入正确的参数。此外,可能需要提醒用户关于权限问题,使用sudo或者root权限运行nmtui。 可能还需要验证配置是否生效,比如使用ip addr查看VLAN接口,或者ping测试PPPoE连接。如果用户遇到问题,可能需要检查日志或使用nmcli检查连接状态。 总结步骤应该是:启动nmtui,添加VLAN或PPPoE连接,填写必要信息,保存并激活,最后验证。同时,引用相关的参考资料,比如引用[3]和[4]中的命令示例,但转换为NMTUI的操作。</think>### 通过 NMTUI 配置 VLAN 和 PPPoE 的步骤 #### 一、配置 VLAN 1. **启动 NMTUI** ```bash sudo nmtui ``` > 选择 **Edit a connection** 进入配置界面[^2][^5] 2. **添加 VLAN 连接** - 点击 **Add** -> 选择 **VLAN** - 设置参数: - **Parent device**:选择物理网卡(如 `ens33`) - **VLAN id**:填写 VLAN 标识号(如 `100`) - **IPv4 Configuration**:选择手动/自动分配 IP(根据网络要求)[^3] - 保存配置并退出 3. **激活 VLAN 连接** ```bash nmcli connection up <VLAN连接名称> ``` #### 二、配置 PPPoE 1. **启动 NMTUI** ```bash sudo nmtui ``` 2. **添加 PPPoE 连接** - 点击 **Add** -> 选择 **DSL/PPPoE** - 设置参数: - **Device**:选择物理网卡(如 `ens33`) - **Username/Password**:填写运营商提供的宽带账号密码 - **IPv6**:按需禁用(若网络不支持)[^4] - 保存配置并退出 3. **激活 PPPoE 连接** ```bash nmcli connection up <PPPoE连接名称> ``` #### 三、验证配置 - **VLAN 验证**: ```bash ip addr show <VLAN接口名称> # 查看VLAN接口状态 ``` - **PPPoE 验证**: ```bash ip route show # 检查默认路由是否指向PPPoE接口 ping 114.114.114.114 # 测试网络连通性 ``` ### 注意事项 1. 需确保 NetworkManager 服务已启用: ```bash systemctl status NetworkManager ``` 2. 嵌入式设备可能需要额外驱动支持 VLAN[^1]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值