Ubuntu 16.04에서 프록시용 서버를 준비하는 방법

Ubuntu 16.04에서 프록시용 서버를 준비하는 방법

Ubuntu 16.04를 사용하여 프록시 서버를 준비하려고 하는데 서버에 다음과 같은 NIC가 있습니다.

enp4s0    Link encap:Ethernet  HWaddr 00:15:c5:f6:c0:36
          inet addr:192.168.0.101  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::215:c5ff:fef6:c036/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:5118 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3065 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:7474529 (7.4 MB)  TX bytes:254689 (254.6 KB)
          Interrupt:16

enp6s0    Link encap:Ethernet  HWaddr 00:08:54:31:8f:79
          inet addr:172.24.3.19  Bcast:172.24.3.255  Mask:255.255.252.0
          inet6 addr: fe80::208:54ff:fe31:8f79/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:7573 errors:0 dropped:334 overruns:0 frame:0
          TX packets:2756 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:756664 (756.6 KB)  TX bytes:881724 (881.7 KB)

enp4s0은 인터넷에 연결된 WAN NIC입니다. enp6s0은 LAN nic입니다.

나는 그것을 다음과 같이 구성했습니다 /etc/network/interfaces.

allow-hotplug enp4s0
iface enp4s0 inet dhcp

allow-hotplug enp6s0
iface enp6s0 inet static
address 172.24.3.19
netmask 255.255.252.0
gateway 172.24.0.1
dns-nameservers 172.24.3.1

enp4s0은 다음에서 추출된 IP를 수신했습니다 /var/lib/dhcp/dhclient.enp4s0.leases.

lease {
  interface "enp4s0";
  fixed-address 192.168.0.101;
  option subnet-mask 255.255.255.0;
  option routers 192.168.0.1;
  option dhcp-lease-time 7200;
  option dhcp-message-type 5;
  option domain-name-servers 192.168.0.1,8.8.8.8;
  option dhcp-server-identifier 192.168.0.1;
  renew 5 2018/06/08 16:03:17;
  rebind 5 2018/06/08 16:59:19;
  expire 5 2018/06/08 17:14:19;
}

수행원Nairabytes.net, 다음과 같이 몇 가지 iptables 규칙을 적용했습니다.

iptables -t nat -A POSTROUTING -o enp4s0 -j MASQUERADE
iptables -A FORWARD -i enp4s0 -o enp6s0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i enp6s0 -o enp4s0 -j ACCEPT

따라서 iptables 규칙은 다음과 같습니다.

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
ACCEPT     all  --  anywhere             anywhere

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

하지만 내가 이해할 수 없는 것은 두 NIC 중 하나만 한 번에 제대로 작동하는 이유입니다. 이 서버는 enp6s0을 통해 LAN과 통신할 수 있지만 인터넷에 연결할 수는 없습니다.

그래서 다음 경로를 적용합니다.

sudo /sbin/route add -net 0.0.0.0 gw 192.168.0.1 enp4s0

그리고 상황은 되돌려졌습니다! 이제 서버는 인터넷에 연결할 수 있지만 LAN에 액세스할 수 없게 됩니다.

내 원래 질문은게이트웨이를 설정하려고 해하지만 enp6s0은 LAN nic이고 VLAN에 연결되어 있기 때문에 불가능해 보입니다. 더 좋게 말하면 이 VLAN에는 이미 게이트웨이(172.24.0.1)가 있고 이 서버를 다른 모든 서브넷에 표시하고 싶습니다(뿐만 아니라 172.24.0.1이지만 다른 12개의 서브넷이 있습니다! 모두 172.24.0.0 넷마스크에 연결되어 있습니다.

그래서 게이트웨이가 아닌 프록시를 키우기로 결정했습니다. 오징어를 설치했는데 오징어 구성을 마치기 전에 작동하려면 연결을 만들어야 합니다. 내 네트워크 구성표는 다음 그림과 같습니다.여기에 이미지 설명을 입력하세요 내가 도대체 ​​뭘 잘못하고있는 겁니까?

관련 정보