相关说明:
eth0是一块物理网卡。eth0.1 eth0.2都是从此设备上虚拟出来的
eth0.1 是vlan1分出的lan口
eth0.2 是vlan分出的wan口
方法一:配置新接口
配置接口
vi /etc/config/network
增加一个接口,这里取名为gm,ip地址要与光猫在一个网段
config interface 'gm'
option ifname 'eth0.2'
option proto 'static'
option netmask '255.255.255.0'
option ipaddr '192.168.1.100'
option gateway '192.168.1.1'
重启网络 /etc/init.d/network restart
配置防火墙
vi /etc/config/firewall
修改 wan 域,加上上面定义的接口 gm
option network 'wan' 修改为 option network 'wan gm'
config zone
option name 'wan'
option network 'wan gm'
option input 'REJECT'
option output 'ACCEPT'
option forward 'REJECT'
option masq '1'
option mtu_fix '1'
重启防护墙 /etc/init.d/firewall restart
访问即可
路由表无需配置,默认有一条
# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0.2
......
......
方法二:配置双IP
使用命令的方式,重启会丢失配置
这个需要重新验证,之前是怎么测试的忘记了。。。。
ifconfig eth0.2:0 192.168.1.100 netmask 255.255.255.0
iptables -t nat -I POSTROUTING -o eth0.2 -d 192.168.1.0/24 -j MASQUERADE
-I 在头部插入规则
-o 匹配出口网卡流出的数据
-d 匹配目的地址
-j 要进行的处理动作 MASQUERADE 改写封包来源 IP 为防火墙 NIC IP,与 SNAT 略有不同,当进行IP伪装时,不需指定要伪装成哪个IP,IP会从网卡直接读取,适用于动态获取IP的情况
关闭
ifconfig eth0.2:0 down
问题解决
出现问题请尝试重启
重启网络命令
/etc/init.d/network reload
重启路由器
reboot
网友评论