若PC上有兩張網(wǎng)卡,需要把網(wǎng)卡A的網(wǎng)絡(luò)共享到網(wǎng)卡B的局域網(wǎng)中,類似路由器wan口到lan口的映射。在windows下十分簡(jiǎn)單,直接在網(wǎng)絡(luò)中心中打開網(wǎng)卡A的共享功能就行,而若在Ubuntu中,需要一下命令:
# sysctl net.ipv4.ip_forward=1
# iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
其中,eth1是網(wǎng)卡A的ifname
以上是在Ubuntu 16.04的做法,在Ubuntu 12.04,可以直接
# echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
Jacob Pan ( jacobpan3g.github.io/cn )