Ubuntu 16.04에서 iptables 를 이용한 포워딩 도움 부탁드립니다.

starsura의 이미지

안녕하세요.

현재 Ubuntu 16.04의 네트워크 환경은 다음과 같습니다.
고정IP로 외부와 연결되어 있습니다.

ifconfig
eth0 Link encap:Ethernet HWaddr 00:0d:3a:b2:cc:5e
inet addr:10.0.0.4 Bcast:10.0.0.255 Mask:255.255.255.0
inet6 addr: fe80::20d:3aff:feb2:cc5e/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:40525 errors:0 dropped:3 overruns:0 frame:0
TX packets:43553 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:25176007 (25.1 MB) TX bytes:19276890 (19.2 MB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:5723 errors:0 dropped:0 overruns:0 frame:0
TX packets:5723 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:946648 (946.6 KB) TX bytes:946648 (946.6 KB)

ip route
default via 10.0.0.1 dev eth0
10.0.0.0/24 dev eth0 proto kernel scope link src 10.0.0.4
168.63.129.16 via 10.0.0.1 dev eth0

nodejs npm의 http-server를 이용해 127.0.0.1:8080 localhost에서 작동중인 웹페이지가 있습니다.
http-server의 옵션을 조정해서 웹페이지를 외부IP에 배포하고 접속 또한 잘 되나...
RPC통신 및 여차저차한 문제로 localhost로 돌릴수 밖에 없는 상황에 왔습니다.

iptables를 이용해 외부아이피 xx.xx.xx.xx:8080 로 접속하면 내부 127.0.0.1:8080에서 작동중인 웹페이지를 보여주고 싶은데,
온종일 iptables와 씨름한 결과 결국 제가 자빠지고 말았습니다. iptables도 처음써봐서 참 난감합니다. 아이고....

도와주시면 대단히 감사드리겠습니다!!!!

chanik의 이미지

아래 페이지에 비슷한 질문과 답변이 나오네요.

http://unix.stackexchange.com/questions/111433/iptables-redirect-outside-requests-to-127-0-0-1

아래와 같이 하면 될 것 같습니다.

$ sudo iptables -t nat -I PREROUTING -p tcp -d 10.0.0.4 --dport 8080 -j DNAT --to-destination 127.0.0.1:8080
$ sudo sysctl -w net.ipv4.conf.eth0.route_localnet=1

첫 줄은 10.0.0.4:8080 을 목적지로 해서 들어오는 패킷을 127.0.0.1:8080 으로 포워딩시키는 규칙이고
두 번째 줄은 외부로부터의 트래픽을 127.0.0.1로 전달할 수 없게 기본설정되어 있는
커널의 제한을 eth0 인터페이스에 대해서만 풀어주는 옵션인 것 같습니다.
(이렇게 풀어주는 것이 보안상 괜찮은 것인지는 모르겠습니다
iptables/sysctl 말고 xinetd를 이용하는 답변도 위 페이지에 있으니 참고하십시오
)

위 명령이 맞다면, 두 줄을 실행하자마자 바로 원하시는 동작이 이뤄질 것인데
일시적인 설정이라서 재부팅 뒤에는 원상복귀될 것이므로
iptables 규칙과 sysctl 규칙이 재부팅 뒤에도 유지되게 신경쓰셔야 합니다.

sysctl 규칙 유지를 위해서는 /etc/sysctl.conf 을 수정하면 되고,
iptables 규칙 유지 방법은 아래 페이지에 세 가지 나오네요.

https://help.ubuntu.com/community/IptablesHowTo#Saving_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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.