我有一台通过以太网连接到互联网的 Raspberry Pi (stretch)。我想将所有网络流量从 wlan0 转发到 eth0,但遇到了麻烦。我是不是漏掉了什么?
// Setting up port forwarding rules
root@raspi:/home/pi# sysctl -w net.ipv4.ip_forward=1
root@raspi:/home/pi# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
root@raspi:/home/pi# iptables -A FORWARD -i eth0 -o wlan0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
root@raspi:/home/pi# iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
// Listing iptable rules
root@raspi:/home/pi# iptables -nvL
Chain INPUT (policy ACCEPT 128 packets, 17968 bytes)
pkts bytes target prot opt in out source destination
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 ACCEPT all -- eth0 wlan0 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
0 0 ACCEPT all -- wlan0 eth0 0.0.0.0/0 0.0.0.0/0
Chain OUTPUT (policy ACCEPT 99 packets, 16689 bytes)
pkts bytes target prot opt in out source destination
// Able to ping Google (8.8.8.8) via eth0
root@raspi:/home/pi# ping 8.8.8.8 -I eth0
PING 8.8.8.8 (8.8.8.8) from 192.168.0.201 eth0: 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=57 time=14.1 ms
// Unable to ping Google via wlan0
root@raspi:/home/pi# ping 8.8.8.8 -I wlan0
PING 8.8.8.8 (8.8.8.8) from 169.254.160.66 wlan0: 56(84) bytes of data.