在OpenWrt路由器上设置虚拟接口和物理接口后,默认情况下它们不能用于直接通信。要实现虚拟接口和物理接口之间的通信,需要进行以下配置:
- 在防火墙中设置允许虚拟接口和物理接口之间的通信:
config zone
option name 'lan'
option input 'ACCEPT'
option output 'ACCEPT'
option forward 'ACCEPT'
option network 'lan'
option defaultrule '1'
- 在网络设置中,添加一个“自定义规则”,指定虚拟接口使用物理接口的MAC地址:
config interface 'virtual'
option proto 'static'
option ipaddr '192.168.1.2'
option netmask '255.255.255.0'
option ifname 'eth0.1'
option delegate '0'
config rule
option in 'virtual'
option lookup 'main'
option priority '100'
config route
option interface 'virtual'
option target '192.168.1.0/24'
option table 'main'
config route
option interface 'virtual'
option target '0.0.0.0'
option gateway '192.168.1.1'
option table 'main'
option metric '10'
- 在虚拟接口中,添加一个“自定义规则”,指定物理接口使用虚拟接口的MAC地址:
config interface 'physical'
option ifname 'eth1'
option proto 'static'
option ipaddr '192.168.1.3'
option netmask '255.255.255.0'
config rule
option in 'physical'
option lookup 'main'
option priority '100'
config route
option interface 'physical'
option target '192.168.1.0/24'
option table 'main'
config route
option interface 'physical'
option target '0.0.0.0'
option gateway '192.168.1.2'
option table 'main'
option metric '10'
注意,上述代码中的接口名和地址需要根据实际情况进行修改。使用以上配置后,虚拟接口和物理接口之间就可以直接进行通信了。