- 我有两个路由器(A,B)。A 使用 IP 192.168.1.1 连接到互联网
- openwrt路由器B通过桥接方式连接A的局域网,静态IP为:192.168.1.111。
- 我正在学习使用 iptables 来控制连接到 B(wlan)的设备。
- 我用手机连接B的wifi,手机IP是192.168.1.100,可以正常上网。
- 我想屏蔽手机的IP,让手机无法连接网络。
參考http://bredsaal.dk/some-small-iptables-on-openwrt-tips
- iptables -A input_wan -s 192.168.1.100 --jump 拒绝
- iptables -A 转发规则 -d 192.168.1.100 --jump 拒绝
但它不起作用。手机仍然可以正常连接到互联网。我尝试了其他链(INPUT、OUTPUT、FORWARD)。太多的链让我感到困惑。
- iptables -I OUTPUT -o br-lan -s 192.168.1.100 -j DROP
并且它不再起作用。
我确定iptables没有问题。
root@OpenWrt:/etc# iptables -L|grep Chain
Chain INPUT (policy ACCEPT)
Chain FORWARD (policy DROP)
Chain OUTPUT (policy ACCEPT)
Chain forward (1 references)
Chain forwarding_lan (1 references)
Chain forwarding_rule (1 references)
Chain forwarding_wan (1 references)
Chain input (1 references)
Chain input_lan (1 references)
Chain input_rule (1 references)
Chain input_wan (1 references)
Chain output (1 references)
root@OpenWrt:/etc# ifconfig
br-lan Link encap:Ethernet HWaddr 0C:82:68:97:57:BA
inet addr:192.168.1.111 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::e82:68ff:fe97:57ba/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:14976 errors:0 dropped:0 overruns:0 frame:0
TX packets:7656 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2851980 (2.7 MiB) TX bytes:1902785 (1.8 MiB)
eth0 Link encap:Ethernet HWaddr 0C:82:68:97:57:BA
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:58201 errors:0 dropped:11 overruns:0 frame:0
TX packets:45012 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:54591348 (52.0 MiB) TX bytes:5711142 (5.4 MiB)
Interrupt:4
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:312 errors:0 dropped:0 overruns:0 frame:0
TX packets:312 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:39961 (39.0 KiB) TX bytes:39961 (39.0 KiB)
mon.wlan0 Link encap:UNSPEC HWaddr 0C-82-68-97-57-BA-00-48-00-00-00-00-00-00-00-00
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:4900 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:32
RX bytes:1223807 (1.1 MiB) TX bytes:0 (0.0 B)
wlan0 Link encap:Ethernet HWaddr 0C:82:68:97:57:BA
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:37346 errors:0 dropped:0 overruns:0 frame:0
TX packets:49662 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:32
RX bytes:3808021 (3.6 MiB) TX bytes:54486310 (51.9 MiB)
root@OpenWrt:/etc/config# cat network
config 'interface' 'loopback'
option 'ifname' 'lo'
option 'proto' 'static'
option 'ipaddr' '127.0.0.1'
option 'netmask' '255.0.0.0'
config 'interface' 'lan'
option 'ifname' 'eth0'
option 'type' 'bridge'
option 'proto' 'static'
option 'ipaddr' '192.168.1.111'
option 'netmask' '255.255.255.0'
option 'gateway' '192.168.1.1'
option dns 192.168.1.1
以及如何使用iptables来控制wlan的网络?
提前致谢,抱歉我的英语不好。
答案1
可能你只需要将 -d(目标 ip)与 -s(源 ip)交换
iptables -A forwarding_rule -s 192.168.1.100 --jump REJECT
输入和输出链仅适用于发送到路由器本身或从路由器本身发出的数据包。