728x90

원문 : 

http://forum.falinux.com/zbxe/?_filter=search&mid=question&search_target=title&search_keyword=iptables&document_srl=533111



현재 1.4.9.1과 커널과 뭔지 모르지만 약간의 문제가 있는듯 합니다. 1.4.8버젼도 같은 증상이 나오네요.

일단 1.4.2버젼으로 해결하였습니다.

1. 먼저 커널을 다음과 같이 컴파일합니다.

[root@JiuHost linux]# make menuconfig

    Networking  --->

      Networking options  --->

         [*] Network packet filtering framework (Netfilter)  --->

             Core Netfilter Configuration  --->

                 <*> Netfilter connection tracking support 

           <*> Netfilter Xtables support (required for ip_tables)

             IP: Netfilter Configuration  --->

                 <*> IPv4 connection tracking support (required for NAT)

                 [*]   proc/sysctl compatibility with old connection tracking (NEW)

           <*> IP tables support (required for filtering/masq/NAT)

           <*>   Packet filtering

           <*>     REJECT target support

           <*>   Full NAT

           <*> MASQUERADE target support

 

2. iptables를 다음과 같이 컴파일합니다.

[root@JiuHost IPTU270]# wget http://ftp.netfilter.org/pub/iptables/iptables-1.4.2.tar.bz2

[root@JiuHost IPTU270]# tar -jxf iptables-1.4.2.tar.bz2 

[root@JiuHost IPTU270]# cd iptables-1.4.2

// 제 경우에는 크로스 컴파일러가 다음 경로에 설치되어 있어 경로설정을 했습니다.

// ./configure시에 크로스 컴파일러를 체크합니다. 반드시 그 이전에 패스를 등록해야 됩니다.

[root@JiuHost iptables-1.4.2]# export PATH=$PATH:/home/youster/Board/cross-compiler/arm-3.4.3/bin

[root@JiuHost iptables-1.4.2]# ./configure --enable-static --host=arm-linux --prefix=/usr/iptables

[root@JiuHost iptables-1.4.2]# make

[root@JiuHost iptables-1.4.2]# make install

// 설치될 경로를 --prefix=/usr/iptables로 하였습니다. 타켓보드에도 똑같은 폴더를 만들어서 그쪽으로 복사할 겁니다.

// 이 설치 경로가 틀리면 실행이 안됩니다.

[root@JiuHost iptables-1.4.2]# cd /usr/iptables/sbin

// 아무래도 스트립을 하는 것이 좋겠지요.

[root@JiuHost sbin]# arm-linux-strip iptables* 

[root@JiuHost sbin]# arm-linux-strip ip6tables*

[root@JiuHost sbin]# cd ..

// 필요없는 폴더를 지웁시다.

[root@JiuHost iptables]# rm -rf share

[root@JiuHost iptables]# rm -rf include

 

3. 이제 타겟보드의 램디스크 이미지에 /usr/iptables 폴더를 만들고

호스트에 있는 폴더를 그대로 복사해옵니다.

먼저 mnt에 마운트되어 있으면,

cd mnt/usr

cp -a /usr/iptables .

 

4. 저는 nat 를 하기 위해서 사용했습니다.

다음과 같이 사용하였는데 참고하실분 참고하세요.

- 발신지 NAT 설정

  패킷이 머신밖으로 나가기 직전(POSTROUTING chain)에 수행되며,

 내부네트워크 사설IP가 외부로 나가기전에 공인 IP로 변환되는 것을 의미한다.

 고정IP라면 SNAT를 이용하여 추가하지만 동적으로 IP주소를 할당받는 경우에는

 발신지 NAT의 특수한 케이스중 하나인 매스커레이딩을 사용한다.

# iptables -A POSTROUTING -t nat -o eth0 -j MASQUERADE

=> eth0를 wan으로 사용하고 eth1을 lan으로 사용한다.

- IP 패킷이 포워딩되도록 설정

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

- 수신지 NAT설정

패킷이 머신안으로 들어온 직후(PREROUTING chain)에 수행되며 실제적으로 내부서버로 포트매핑을 수행한다.

나는 eth1에 물려 있는 192.168.129.10으로 7021번 포트를 포워딩했다.

먼저 모든 포트매핑을 지우자.

# iptables -F PREROUTING -t nat

매핑할 포트를 지정하자.

# iptables -A PREROUTING -t nat -p tcp --dport 7021 -i eth0 -j DNAT --to 192.168.129.10:7021

확인

# iptables -t nat -L

Chain PREROUTING (policy ACCEPT)

target     prot opt source               destination

DNAT       tcp  --  anywhere             anywhere            tcp dpt:7021 to:192.168.129.10:7021

Chain POSTROUTING (policy ACCEPT)

target     prot opt source               destination

MASQUERADE  all  --  anywhere             anywhere

Chain OUTPUT (policy ACCEPT)

target     prot opt source               destination



======================================================

1~3까지 test했을 때 정상적으로 동작 확인.

728x90

+ Recent posts