Skip to content

Instantly share code, notes, and snippets.

@ixqbar
Last active April 19, 2017 08:48
Show Gist options
  • Save ixqbar/4ba94e6fea0183cda3a61de49b21844f to your computer and use it in GitHub Desktop.
Save ixqbar/4ba94e6fea0183cda3a61de49b21844f to your computer and use it in GitHub Desktop.
linux

###打开ip转发

echo 1 > /proc/sys/net/ipv4/ip_forward 

###查看

iptables -L -n

###清空

iptables -F
iptables -X
iptables -Z
@ixqbar
Copy link
Author

ixqbar commented Jan 24, 2017

iptables

@ixqbar
Copy link
Author

ixqbar commented Mar 16, 2017

  • SNAT用来修改源地址IP,而DNAT用来修改目标IP地址,目标端口;SNAT只能用在nat表的POSTROUTING链,而DNAT只能用在nat表的PREROUTING链和OUTPUT链

###跨机转发 (将1.1.1.1的81端口的访问转发到2.2.2.2的80端口)

iptables -t nat -A PREROUTING -d 1.1.1.1 -p tcp --dport 81 -j DNAT --to-destination 2.2.2.2:80
iptables -t nat -A POSTROUTING  -d 2.2.2.2 -p tcp --dport 80 -j SNAT --to-source 1.1.1.1

###本地转发 (80转发到8080)

iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-ports 8080
iptables -t nat -A OUTPUT -p tcp --dport 80 -j DNAT --to-ports 8080 

@ixqbar
Copy link
Author

ixqbar commented Apr 19, 2017

cat 1.log | awk '{sum+=$1} END {print sum}'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment