[완료] iptables로 특정도메인에 따라 포트포워딩을 하고 싶은데 이상하게 되네요.

viper9의 이미지

CentOS 6.2 리눅스서버가 한대 있습니다.

여기에는 네임서버, 웹서버, FTP 서버 등등이 설치되어 있으며 ns.aaa.com 도메인으로 네임서버를 운영중이고 www.aaa.com, ftp.aaa.com 등의 도메인이 부여되어 있습니다.

이 서버에 QEMU-KVM으로 윈도우2008을 설치했습니다.

이 리눅스서버로 접속하면 윈도우2008로 접속하게 만들고 싶습니다.

/etc/sysconfig/iptables 파일에 다음과 같이 스크립트를 작성했습니다. (192.168.122.95가 윈도우2008로 접속할 수 있는 IP입니다.)

-A POSTROUTING -o eth1 -j MASQUERADE
-A PREROUTING -p tcp -m tcp --dport 50000 -j DNAT --to-destination 192.168.122.95:50000
-A PREROUTING -p tcp -m tcp --dport 50080 -j DNAT --to-destination 192.168.122.95:50080
 
-A PREROUTING -p tcp -m tcp --dport 50021 -j DNAT --to-destination 192.168.122.95:50021
-A PREROUTING -p tcp -m tcp --dport 59000:59999 -j DNAT --to-destination 192.168.122.95
 
-A PREROUTING -p tcp -m tcp --dport 53389 -j DNAT --to-destination 192.168.122.95:53389
-A PREROUTING -p udp -m udp --dport 53389 -j DNAT --to-destination 192.168.122.95:53389
 
-A POSTROUTING -o eth1 -s 192.168.122.95

여기까지는 제가 원하는대로 잘 접속됩니다.

5000, 50080등의 포트는 포트포워딩이 잘 되서 윈도우로 접속이 됩니다.

여기에서 하나 더 하고 싶은건 www.aaa.com 으로 접속했을 때는 리눅스 서버의 웹서버가 응답하고 windows.aaa.com으로 접속할 때는 윈도우 서버가 응답하도록 하려고 합니다.

그래서 다음과 같은 스크립트를 추가했습니다.

-A PREROUTING -p tcp -d windows.aaa.com --dport 80 -j DNAT --to-destination 192.168.122.95:80

이렇게 추가하고 나서 iptables를 재시작하고 보니 windows.aaa.com 뿐만 아니라 www.aaa.com, ftp.aaa.com 등 모든 도메인이 다 윈도우 서버의 IIS가 응답합니다;;;;;;;;

그래서 iptables -t nat -L 명령을 쳐보니 다음과 같이 나옵니다.

[root@aaa viper9]# iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination
DNAT       tcp  --  anywhere             anywhere            tcp dpt:50000 to:192.168.122.95:50000
DNAT       tcp  --  anywhere             anywhere            tcp dpt:50080 to:192.168.122.95:50080
DNAT       tcp  --  anywhere             anywhere            tcp dpt:50021 to:192.168.122.95:50021
DNAT       tcp  --  anywhere             anywhere            tcp dpts:59000:59999 to:192.168.122.95
DNAT       tcp  --  anywhere             anywhere            tcp dpt:53389 to:192.168.122.95:53389
DNAT       udp  --  anywhere             anywhere            udp dpt:53389 to:192.168.122.95:53389
DNAT       tcp  --  anywhere             ns.aaa.com        tcp dpt:http to:192.168.122.95:80
 
Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination
MASQUERADE  all  --  anywhere             anywhere
 
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

저는 windows.aaa.com만 포트포워딩하도록 해놨는데 목표도메인이 ns.aaa.com 으로 잡혀있더군요. 그러니 당연히 모든 도메인이 다 윈도우 서버로 접속되었던 것이구요.

도대체 어디가 잘못된 것인지 아무리 찾아도 알 수가 없어서 여기에 질문드립니다.

windows.aaa.com 은 192.168.122.95 서버의 80번 포트로, 나머지 도메인은 리눅스 서버가 응답하도록 하고 싶습니다.

mog422의 이미지

iptables 에 입력하는 인자값은 아이피로 바뀌어서 입력이 됩니다. 원하시대로 하시려면 ISP에서 아이피를 하나 더 받아 오시거나, 80포트 요청을 nginx 같은 리버스 프록시에 물리신 후에 리버스 프록시를 통해서 각각의 웹서버로 연결해주시면 될듯 합니다.

viper9의 이미지

정말 감사합니다. 이유를 알고나니 속시원해지네요.

이런 답변이 필요했는데 아무리 검색해도 안나와서... 휴. ㅠㅠ

서버에 nginx가 설치되어있긴하나 실험용으로만 가끔 켜서 쓰고 실제로는 apache를 서비스용도로 쓰는지라 apache 웹서버의 mod_proxy 모듈로써 해결했습니다.

windows.aaa.com 으로 virtualhost 하나 만들고

ServerAdmin info@aaa.com
ServerName windows.aaa.com
ProxyPass / http://192.168.122.95/
ProxyPassReverse / http://192.168.122.95/

이렇게 해주니까 원하는대로 작동합니다. ^^

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.