[NAT/투명프록시] Linux를 이용한 투명 프락시 서버 구축 문의

자일자일의 이미지

Redhat Linux를 이용한 NAT 서버 구축 관련하여 질문 드립니다.

첨부한 파일에 작성된 구성도와 같은 테스트베드가 있습니다.
Server A/B 모두 사설 IP가 할당되어있습니다.

Server B에는 라우터에서 NAT 설정을 하여 외부로 공인IP를 가지고
나갈 수 있게 설정하여 HTTP 통신이 가능하게 설정된 상태입니다.

Server A/B는 서로 제한 없이 통신할 수 있도록 방화벽 정책이 설정되어 있어요.

제가 구현하고 싶은 것은 네트워크 구성 변경 없이
Server A에서도 외부와 통신(HTTP)을 하고 싶습니다.

Server B에 squid 설치 후
Server A에 아래와 같이 변수 설정하여 통신 되는 것은 확인했습니다.
export http_proxy=http://192.168.200.5:3128/
export https_proxy=http://192.168.200.5:3128/

그런데 이렇게 프락시를 지정하지 않고
iptables을 이용한 투명 프락시를 구축하고 싶어서 아래 URL 참고하여
설정 후 확인해보니 Server B로 패킷이 포워딩 되지 않네요.

제가 구현하려는 구성이 기술적으로 가능한 내용인지 궁금합니다.

요약하면.. Server A에서 Destination:80 으로 요청 시
Server B를 게이트웨이 삼아서 데이터를 주고받았으면 합니다.

아래 참고 URL 내용이 제가 원하는 내용인 듯한데 여러 번 해봐도 성공을 못 했어요.
도움 부탁 드려요. 감사합니다.

-참고 URL
http://linuxholic.tistory.com/73
http://tldp.org/HOWTO/TransparentProxy.html

File attachments: 
첨부파일 크기
Image icon LAB01.png50.39 KB
자일자일의 이미지

[root@ServerA tmp]# echo 1 > /proc/sys/net/ipv4/ip_forward

[root@ServerA tmp]# iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
DNAT tcp -- anywhere anywhere tcp dpt:http to:192.168.200.5.80:80

Chain POSTROUTING (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination

위처럼 설정 후 tcpdump 이용하여 패킷 확인해 보면 패킷 포워딩이 적용되지 않은게 확인되요.
[root@ServerA tmp]# tcpdump dst port 80 -nn
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
22:45:52.963430 IP 192.168.100.5.58516 > 74.125.128.102.80: Flags [S], seq 4171447276, win 14600, options [mss 1460,sackOK,TS val 17890564 ecr 0,nop,wscale 7], length 0
22:45:55.963061 IP 192.168.100.5.58516 > 74.125.128.102.80: Flags [S], seq 4171447276, win 14600, options [mss 1460,sackOK,TS val 17893564 ecr 0,nop,wscale 7], length 0

자일자일의 이미지

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to 192.168.200.5:80
위에 적용된 iptables 규칙입니다.

익명 사용자의 이미지

많이 늦었겠지만, 다른 분들도 볼 수 있으니 답을 적습니다.

위에 적은 iptables 규칙은 ServerA가 라우터로 동작하는 경우에 적용됩니다.
예를 들어, PC-A 가 ServerA를 라우터로 지정했을 경우 다음과 같이 동작합니다.

PC-A ==> ServerA [ mangle PREROUTING -> nat PREROUTING
-> (라우팅 결과 패킷이 외부로 나가야 함. 즉 forwarding 필요)
-> mangle FORWARD -> filter FORWARD
-> mangle POSTROUTING -> nat POSTROUTING ]
==> (다음 단계의 장비)

그리고 Destination NAT (DNAT)은 "nat PREROUTING" 체인에서만 정의할 수 있습니다.
( "nat POSTROUTING" 이나 "nat OUTPUT" 체인에서는 DNAT 설정 불가능합니다.
왜냐하면 이미 라우팅 처리를 끝낸 상태이기 때문에 목적지를 변경할 수 없습니다.)

따라서, PC-A는 위 iptables 규칙에 있는 DNAT 적용을 받습니다.

한편, ServerA에서 만들어진 패킷은 위와는 다르게, 아래와 같이 처리됩니다.

ServerA에서 패킷 생성 (예, 브라우저에서 외부로 연결 시도) -> (라우팅 결과 패킷이 외부로 나가야 함. 즉, OUTPUT 필요)
-> mangle OUTPUT -> nat OUTPUT -> filter OUTPUT
-> mangle POSTROUTING -> nat POSTROUTING
==> 외부로 나감.

아래 그림을 이해하려고 해보시기 바랍니다.
( http://resources.infosecinstitute.com/how-to-use-iptables/ 중간에 있는 흐름도 )

한글로 된 것은 쉽게 못찾겠네요...

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.