역방향 NAT 액세스를 위한 듀얼 NIC

역방향 NAT 액세스를 위한 듀얼 NIC

이 목표를 달성하려면 도움이 필요합니다.

Internet
    <-- TP_LINK Router(192.168.0.1)
        <-- PC1(eth0:192.168.0.8)
        <-- PC2(eth0:192.168.0.81)

케이블을 사용하여 PC2 eth1을 PC3 eth0에 연결하고 PC2 eth1 IPV4 설정을 "다른 컴퓨터와 공유"로 구성하면 PC2와 PC3이 IP 아래에 도달합니다.

    PC2(eth1:10.42.0.1)
        <-- PC3(eth0: 10.42.0.169)

이제 PC1에서 "10.42.0.169"를 ping할 수 있도록 경로 또는 iptables에서 작업을 수행하고 싶습니다.

이것이 가능한가? 다음은 내가 시도한 것입니다.

  • TP_LINK 라우터의 정적 경로 테이블을 구성합니다: 10.42.0.0(대상) - 255.255.255.0(넷마스크) - 192.168.0.81(게이트웨이).

이제 PC1에서 결과를 얻습니다.

$ traceroute 10.42.0.169
traceroute to 10.42.0.169 (10.42.0.169), 64 hops max, 52 byte packets
1  192.168.0.1 (192.168.0.1)  4.018 ms  0.905 ms  0.768 ms
2  ay11 (192.168.0.81)  1.140 ms  1.273 ms  1.482 ms
3  ay11 (192.168.0.81)  1.104 ms  1.041 ms  1.127 ms

PC2가 패킷을 10.42.0.0/24로 전달할 수 있다면 모든 것이 완벽할 수도 있다는 것을 알 수 있습니다.

PC2의 구성은 다음과 같습니다.

$ route
default         192.168.0.1     0.0.0.0         UG    100    0        0 eth1
10.42.0.0       *               255.255.255.0   U     100    0        0 eth0
link-local      *               255.255.0.0     U     1000   0        0 eth1
192.168.0.1     *               255.255.255.255 UH    100    0        0 eth1

$ sudo iptables -L
[sudo] password for mlhch: 
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     udp  --  anywhere             anywhere             udp dpt:bootps
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:bootps
ACCEPT     udp  --  anywhere             anywhere             udp dpt:domain
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:domain

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             10.42.0.0/24         state RELATED,ESTABLISHED
ACCEPT     all  --  10.42.0.0/24         anywhere            
ACCEPT     all  --  anywhere             anywhere            
REJECT     all  --  anywhere             anywhere             reject-with icmp-port-unreachable
REJECT     all  --  anywhere             anywhere             reject-with icmp-port-unreachable

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Route 또는 iptables로 무엇을 해야 합니까?

감사해요!

답변1

이것을 설정해 보세요. PC2가장 먼저 할 일은 IP 전달을 활성화하는 것입니다. 이는 다음 중 하나를 사용하여 수행됩니다.

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

그런 다음 트래픽을 전달하라는 규칙을 추가하겠습니다.

sudo iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT
sudo iptables -A FORWARD -i eth0 -o eth1 -m state --state ESTABLISHED,RELATED -j ACCEPT

답변2

당신의 노력에 감사드립니다.

/proc/sys/net/ipv4/ip_forward의 경우 이미 "1"이었고 /etc/sysctl.conf에서 net.ipv4.ip_forward=1을 구성했습니다.

iptables 명령을 실행했는데 Chain FORWARD 섹션에 아래 두 줄만 추가되었습니다.

ACCEPT     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED

그러면 기적은 일어나지 않습니다. 하지만 그 때문에 2개의 REJECT 라인이 눈에 띄었습니다.

REJECT     all  --  anywhere             anywhere             reject-with icmp-port-unreachable
REJECT     all  --  anywhere             anywhere             reject-with icmp-port-unreachable

삭제하면 모든 것이 완벽하게 작동합니다! 실제로 새로 추가된 줄도 삭제하고 "ACCEPT all -- Anywhere Anywhere" 줄 1개만 유지합니다.

관련 정보