mynote/ubuntu/iptables.md
2018-09-16 11:16:52 +08:00

969 B
Executable File

linux 下使用iptables 做路由转发

环境

两台设备:
    ubuntu 16.04
        eth0    192.168.1.2/24      192.168.1.2
        wlan0   10.138.177.83       *.*.*.*
    raspberry pi b+
        eth0    192.168.1.10/24     192.168.1.2

iptables 命令

参考自 http://man.linuxde.net/iptables

iptables -t 表名 <-A/I/D/R> 规则链名 [规则号] <-i/o 网卡名> -p 协议名 <-s 源IP/源子网> --sport 源端口 <-d 目标IP/目标子网> --dport 目标端口 -j 动作

转发80端口到其他端口

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 4000

设置静态ip

sudo nano /etc/network/interfaces

auto eth0
iface eth0 inet static
address 192.168.8.100
netmask 255.255.255.0
gateway 192.168.8.2
dns-nameserver 119.29.29.29

sudo /etc/init.d/networking restart # 重启网络