一、Untagged端口
1、Untagged端口定义:
Untagged端口是设备的物理接口,它没有特定的VLAN ID标识。当一个数据包被发送到Untagged端口时,交换机会自动带上默认的VLAN ID标识,这个标识是由交换机提前配置好的。
2、Untagged端口的使用场景:
当一个网站只有一段物理网络线路,但是想要同时实现不同 VLAN ID 的标记,就需要使用Untagged端口。此时,交换机会自动为这些数据包加上指定的 VLAN ID 标识。
3、Untagged端口的代码示例:
以下是使用Python通过SSH协议配置Untagged端口的代码示例:
import paramiko ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect('192.168.1.1', username='admin', password='password') stdin, stdout, stderr = ssh.exec_command('configure terminaln' 'interface gigabitethernet 1/0/1n' 'switchport mode accessn' 'vlan 100n' 'exitn' 'exitn' 'write memoryn') ssh.close()
二、Tagged端口
1、Tagged端口定义:
Tagged端口是设备的物理接口,在发送和接收数据包时添加有VLAN ID标识。通常情况下,Tagged端口连接的设备都会理解VLAN ID标识,并进行相应的处理。
2、Tagged端口的使用场景:
当一个物理网络线路需要同时提供多个不同VLAN ID标识的服务时,需要使用Tagged端口。这个场景在交换机之间的连接中非常常见。
3、Tagged端口的代码示例:
以下是使用Python通过SSH协议配置Tagged端口的代码示例:
import paramiko ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect('192.168.1.1', username='admin', password='password') stdin, stdout, stderr = ssh.exec_command('configure terminaln' 'interface gigabitethernet 1/0/2n' 'switchport mode trunkn' 'switchport trunk allowed vlan 100,200,300n' 'exitn' 'exitn' 'write memoryn') ssh.close()
三、Untagged端口与Tagged端口的区别
1、作用不同:
Untagged端口主要用于将一个物理网络线路划分成多个VLAN ID标识的虚拟网络线路,而Tagged端口则用于在交换机之间传递多个VLAN ID标识的数据包。
2、处理机制不同:
Untagged端口使用交换机提前配置好的默认的VLAN ID来处理数据包,而Tagged端口则在每个数据包的头部添加VLAN ID标识。
3、使用场景不同:
Untagged端口通常应用于连接客户设备,如PC、服务器等;而Tagged端口通常应用于连接交换机、路由器、防火墙等网络设备之间。
4、代码示例:
以下是Untagged端口和Tagged端口的代码示例:
# 配置Untagged端口 import paramiko ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect('192.168.1.1', username='admin', password='password') stdin, stdout, stderr = ssh.exec_command('configure terminaln' 'interface gigabitethernet 1/0/1n' 'switchport mode accessn' 'vlan 100n' 'exitn' 'exitn' 'write memoryn') ssh.close() # 配置Tagged端口 import paramiko ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect('192.168.1.1', username='admin', password='password') stdin, stdout, stderr = ssh.exec_command('configure terminaln' 'interface gigabitethernet 1/0/2n' 'switchport mode trunkn' 'switchport trunk allowed vlan 100,200,300n' 'exitn' 'exitn' 'write memoryn') ssh.close()