![如何使用 Debian 共享我的 LAN 互联网连接?](https://linux22.com/image/564990/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%20Debian%20%E5%85%B1%E4%BA%AB%E6%88%91%E7%9A%84%20LAN%20%E4%BA%92%E8%81%94%E7%BD%91%E8%BF%9E%E6%8E%A5%EF%BC%9F.png)
我正在尝试将我的 Debian 服务器设为我的 LAN 的路由器。
我有两个接口:eth0 通过 PPPoE 连接到互联网,eth1 连接到 LAN。我在 sysctl net.ipv4.ip_forward=1 中打开了转发,并禁用了 iptables(策略接受)。我可以 ping 网关,但无法 ping 互联网上的任何东西。
答案1
您需要使用 NAT 来与您的 LAN 共享互联网连接。
例子:
iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE
iptables --append FORWARD --in-interface eth1 -j ACCEPT
有关详细信息,请参阅 HowtoForge 上的指南: http://www.howtoforge.com/nat_iptables
答案2
启用 IP 转发 (又称路由) 是不够的;您还必须将内部网络 NAT 到外部 IP。
禁用 netfilter 并不能达到这个目的;你需要 Rusty 的一行伪装规则:
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE