OS/Linux

iptable을 이용한 ip forward

아르비스 2017. 4. 12. 10:27


all the packets coming to 192.168.12.87 and port 80 will be forwarded to 192.168.12.77 port 80.



192.168.12.87:80   ==forward==> 1192.168.12.77:80

이런경우, 다음과 같이 설정하면, 된다



#!/bin/sh

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

iptables -F
iptables -t nat -F
iptables -X

iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 192.168.12.77:80 

iptables -t nat -A POSTROUTING -p tcp -d 192.168.12.77 --dport 80 -j SNAT --to-source 192.168.12.87 


[iptable control]

- 끄기 / 켜기

service iptables stop
/etc/init.d/iptables stop
service iptables start
/etc/init.d/iptables start

상태

# iptables -L

[root@yum.repos.d]# iptables -L

Chain INPUT (policy ACCEPT)

target     prot opt source               destination


Chain FORWARD (policy ACCEPT)

target     prot opt source               destination


Chain OUTPUT (policy ACCEPT)

target     prot opt source               destination