Motive

공공기관이나 학교 등의 경우 SSH 포트인 22번을 보안상의 이유로 게이트웨이 단에서부터 막아두는 경우가 있다. 기관에 정식으로 특정 IP 주소의 포트 오픈을 요청하거나 VPN 등을 사용하는 방법이 있으나, 그것이 귀찮은 경우 어떤 사정으로 항시 오픈되어 있는 다른 포트를 SSH 접속에 쓸 수 있다. (기관이 상시 개방할 가능성이 높은 포트 목록들: https://ko.wikipedia.org/wiki/TCP/UDP%EC%9D%98_%ED%8F%AC%ED%8A%B8_%EB%AA%A9%EB%A1%9D) 대표적으로 80번 포트, 443번 포트 등은 HTTP 프로토콜(사람들이 학교 홈페이지 정돈 접속할 수 있어야 하니)에 사용되므로 대개 항시 오픈되어 있다.

물론 보안상 권장할만한 방법은 아니지만 이러한 상시 개방 포트들을 나만의 포트로 사용하는 것은 유용하다. 접속하고자 하는 네트워크 내의 모든 터미널을 다 바꾸기는 찝찝하기도 하고 귀찮기도 하여 백도어용으로 사용할 노드 한 대만 포트를 열어두고 나머지는 그 노드를 경유하여 접속하는 것이 나의 일반적인 방식이다.

그마저도 귀찮을 때 백도어 노드에 iptables를 통해 포트포워딩을 해주어 특정 포트를 사용하여 한 번에 원하는 서버 접속을 할 수 있게 하기 위한 방법을 소개한다.

출처: http://webterror.net/?p=1622

위의 다이어그램에서 볼 수 있듯, 포워딩을 해줄 노드의 역할은 그냥 패킷을 스쳐지나가듯 흘려보내주기만 하면 되므로 그림상에서 PREROUTING, FORWARD, POSTROUTING 쪽의 규칙만 어떻게 잘 해주면 어찌어찌 돌아갈 것 같다고 대충 눈치를 챌 수 있다. 그렇다면 문제는 그걸 구체적으로 어떻게 하느냐…?

환경

작업 노드: 라즈베리 파이3

OS: Raspbian 8

Procedure

참고 링크: https://wikileaks.org/ciav7p1/cms/page_16384684.html

i) Enable IP Forwarding

sudo sysctl net.ipv4.ip_forward=1

의 커맨드를 입력한다. 혹은 config 파일을 직접 수정해도 된다.

sudo vi /etc/sysctl.conf

나의 경우에는 config 파일을 열어보았더니 이미 설정이 1로 되어 있어서 굳이 뭔가를 바꿀 필요는 없었다. 이는 운영체제마다 기본 설정이 다를 것이므로 체크를 해주어야 할 것이다.

ii) Forward traffic on port [port] to IP [server] on port 22

sudo iptables -t nat -A PREROUTING -p tcp --dport [port] -j DNAT --to-destination [server]:22

[port] 자리에 포워딩할 포트, [server] 자리에 라즈베리를 경유해 접속할 서버의 주소. 예를 들어 라즈베리의 1111번 포트를 1.1.1.1의 주소를 가진 서버로 포워딩하고 싶다면,

sudo iptables -t nat -A PREROUTING -p tcp --dport 1111 -j DNAT --to-destination 1.1.1.1:22

iii) Nothing for FORWARD

필터링 따위는 없이 모든 패킷이 이랏샤이마세이므로 FORWARD에 해당하는 규칙은 아무것도 정하지 않을 것이다. 물론 FORWARD chain의 기본정책은 ACCEPT여야 할 것이다. ACCEPT로 안되어 있다면,

sudo iptables -P FORWARD ACCEPT

iv) Ask iptables to Masquerade

sudo iptables -t nat -A POSTROUTING -j MASQUERADE

클라이언트의 주소가 아니라 라즈베리의 주소로 패킷을 다시 써야 한다. (마스커레이딩은 나도 완벽하게 이해한 것은 아니므로 나중에 기회가 되면 다뤄보겠음.)

v) Test

아무 클라이언트에서 라즈베리파이의 1111 포트로 ssh 접속을 시도해본다. 정상적으로 세팅이 되었다면 ssh 접속이 라즈베리가 아닌, 포워딩된 서버로 될 것이다. 또한 호스트 입장에서는 ssh 세션을 외부 주소가 아닌 라즈베리 파이가 접속한 것으로 인식할 것이다.

vi) Save iptables rules

iptables에 기록된 규칙들은 시스템을 리부트하면 다 사라져버린다. 매번 리부팅 할때마다 다시 위의 설정을 해주면 되지만, 귀찮은 사람이라면 자동으로 해주면 되는데 이건 위의 참고 링크에서 방법을 확인할 수 있다.

2019. 11. 8. 추가)

위의 링크는 좀 구닥다리 방식인 듯 하고 아래 링크가 더 나은 것 같음.

https://www.thomas-krenn.com/en/wiki/Saving_Iptables_Firewall_Rules_Permanently


iptables로 이것저것 세팅하다보니 유무선공유기라는게 사실 별게 아니라 이런 식으로 동작하는건가 싶다.

카테고리: Linux

78개의 댓글

wmdolls · 2021-10-12 19:07

ラブドール 小型 Great post. I was checking constantly this blog and I’m impressed! You can reduce stress with a sex doll. You can hug a real sex doll, hug and sleep, and feel a loyal companion. You can take your

unhealthy cholesterol · 2021-10-15 08:19

I want gathering useful info, this post has got me even more info!

My site – unhealthy cholesterol

drug crime · 2021-10-16 07:07

Wow! This blog looks just like my old one! It’s on a completely different subject but it has pretty much the same page layout and design.
Excellent choice of colors!

my website – drug crime

low-carb diet · 2021-10-21 21:14

I?m amazed, I have to admit. Seldom do I come across a blog that?s equally educative
and engaging, and without a doubt, you have hit the nail
on the head. The issue is something that not enough folks are speaking
intelligently about. I’m very happy I stumbled across this
in my hunt for something concerning this.

My homepage low-carb diet

j.mp · 2021-10-22 19:13

Hey there I am so delighted I found your webpage, I really
found you by error, while I was looking on Yahoo for something else, Nonetheless I am
here now and would just like to say kudos for a tremendous post and
a all round thrilling blog (I also love the theme/design),
I don’t have time to go through it all at the minute but I have saved it and also added your
RSS feeds, so when I have time I will be back to read much more,
Please do keep up the awesome job. part time jobs hired in 30
minutes https://parttimejobshiredin30minutes.wildapricot.org/

fat loss · 2021-10-25 10:42

Thank you for sharing with us, I think this website truly stands out :
D.

Also visit my homepage: fat loss

ways to have better sex · 2021-10-25 10:57

I like this post, enjoyed this one regards for putting up.

Here is my site; ways to have better sex

diets bullshit · 2021-10-25 11:28

I wish to voice my passion for your kind-heartedness giving support to people who absolutely need guidance on this one idea.
Your special dedication to passing the message across had become remarkably advantageous and have
always helped ladies like me to arrive at
their pursuits. Your entire insightful recommendations entails so much to me and somewhat more to my colleagues.
Best wishes; from each one of us.

Stop by my web blog :: diets bullshit

favourite asmr · 2021-10-25 11:29

I enjoy the efforts you have put in this, appreciate it for
all the great articles.

my web blog; favourite asmr

watching asmr · 2021-10-25 11:53

I like the valuable info you provide in your articles. I’ll bookmark your weblog and check again here regularly.
I am quite sure I’ll learn plenty of new stuff right here!
Best of luck for the next!

Take a look at my webpage :: watching asmr

Candace · 2021-10-25 11:58

Hello there! Quick question that’s totally off topic.

Do you know how to make your site mobile friendly?

My blog looks weird when browsing from my iphone.
I’m trying to find a template or plugin that might
be able to resolve this problem. If you have any suggestions,
please share. Cheers!

cannabis seeds exist · 2021-10-25 12:10

Hi there, You have done a great job. I’ll certainly digg it
and personally suggest to my friends. I’m sure they’ll
be benefited from this website.

Feel free to surf to my web-site :: cannabis seeds exist

Casino Cat обзор · 2021-10-25 12:13

Весь игровой ассортимент поставляется провайдерами, которые устанавливают лицензионные процент отдачи.

Here is my webpage :: Casino Cat обзор

Katrin · 2021-10-25 12:19

It?s hard to come by educated people for this topic,
however, you seem like you know what you?re talking about!
Thanks

Also visit my web site … Katrin

Candace · 2021-10-25 12:53

You really make it appear so easy together with
your presentation but I to find this matter to be actually one
thing which I think I might never understand. It seems too complicated and very vast for me.
I’m having a look ahead in your subsequent submit, I will
try to get the hold of it!

yeast infection · 2021-10-25 13:10

Some truly interesting info, well written and loosely user genial.

Visit my web-site yeast infection

male sexual health enhancers · 2021-10-25 13:24

Hello.This post was extremely interesting, especially since I was
browsing for thoughts on this issue last Tuesday.

My homepage; male sexual health enhancers

http://www.a913.vip/forum.php?mod=viewthread&tid=3332223 · 2021-10-25 13:38

I got what you intend,saved to my bookmarks,
very nice internet site.

Look into my blog post :: http://www.a913.vip/forum.php?mod=viewthread&tid=3332223

inexpensive skin care products · 2021-10-25 13:38

Hmm it looks like your blog ate my first comment (it was
super long) so I guess I’ll just sum it up what I had written and
say, I’m thoroughly enjoying your blog. I
as well am an aspiring blog writer but I’m still new
to the whole thing. Do you have any suggestions for first-time blog writers?

I’d definitely appreciate it.

Also visit my blog; inexpensive skin care products

Roger · 2021-10-25 13:49

I’m not that much of a online reader to be honest but your blogs really nice, keep it up!
I’ll go ahead and bookmark your website to come back down the road.
All the best

acne medication · 2021-10-25 14:24

My spouse and I stumbled over here different website and thought I may as well check things out.
I like what I see so now i am following you. Look forward to going over your web page again.

My website – acne medication

drug rehab centres · 2021-10-25 14:28

Right here is the right website for anyone who would like to find out
about this topic. You understand a whole lot its almost hard to argue with you (not that I actually would want to?HaHa).

You certainly put a brand new spin on a subject that’s been written about for ages.

Excellent stuff, just excellent!

my web page: drug rehab centres

Shoshana · 2021-10-25 14:43

My family always say that I am wasting my time here at web,
but I know I am getting experience everyday by reading thes
pleasant content.

bbs.yunweishidai.com · 2021-10-25 14:59

Great info. Lucky me I came across your site by accident (stumbleupon).

I’ve book-marked it for later!

Feel free to surf to my webpage bbs.yunweishidai.com

best skin · 2021-10-25 15:26

Now I am going to do my breakfast, afterward having my breakfast
coming again to read further news.

Here is my page … best skin

lose fat fast · 2021-10-25 15:40

Whoah this weblog is fantastic i love studying your posts.
Stay up the great paintings! You realize, many persons are looking around for this information, you can help them greatly.

Check out my web page lose fat fast

Leonor · 2021-10-25 16:11

Hurrah, that’s what I was seeking for, what a stuff!
existing here at this webpage, thanks admin of this
web page.

quit smoking remedies · 2021-10-25 16:12

Wonderful article! We will be linking to this particularly great article on our site.
Keep up the great writing.

Also visit my site: quit smoking remedies

bbs.yunweishidai.com · 2021-10-25 16:20

Some truly interesting info, well written and loosely user friendly.

Feel free to visit my web-site – bbs.yunweishidai.com

Christoper · 2021-10-25 16:22

great points altogether, you just received a new reader.
What would you recommend about your put up that you made a few days ago?

Any positive?

simplified skin care · 2021-10-25 16:36

You have made some really good points there. I looked on the internet to find out more about the issue and found
most individuals will go along with your views on this website.

My webpage :: simplified skin care

instagram takipçi satın al · 2021-10-25 16:42

It’s difficult to find educated people on this subject,
but you sound like you know what you’re talking about!
Thanks

cannabis dispensaries-san diego · 2021-10-25 16:50

I am really loving the theme/design of your blog. Do you ever run into any web browser
compatibility problems? A few of my blog readers have complained about my blog not
operating correctly in Explorer but looks great in Safari.
Do you have any advice to help fix this issue?

Feel free to surf to my web site; cannabis dispensaries-san diego

videos haring · 2021-10-25 17:12

Stunning quest there. What occurred after? Good luck!

my web-site – videos haring

www.hltkd.tw · 2021-10-25 17:38

I saw a lot of website but I believe this one contains something special in it.

Here is my web blog: http://www.hltkd.tw

lost weight · 2021-10-25 17:43

A person necessarily help to make critically posts I would state.

This is the first time I frequented your web page and so far?
I amazed with the research you made to create this actual publish
amazing. Wonderful task!

Feel free to visit my blog post: lost weight

hermetics.org · 2021-10-25 18:33

You made some clear points there. I looked on the internet for the subject matter and found most individuals
will consent with your blog.

Here is my blog :: hermetics.org

making money online · 2021-10-25 18:39

Thank you for the good writeup. It in fact was a
amusement account it. Look advanced to far added agreeable from
you! However, how could we communicate?

my web blog; making money online

Rodrick · 2021-10-25 18:54

This is a very good tip especially to those fresh to the blogosphere.
Simple but very accurate info… Many thanks for sharing this one.

A must read post!

www.fles.hlc.edu.tw · 2021-10-25 19:03

Thanks a lot for sharing this with all folks you really know what you are
speaking approximately! Bookmarked. Please additionally seek advice from my site =).
We may have a hyperlink trade agreement among us!

Feel free to surf to my web page – http://www.fles.hlc.edu.tw

http://cozumubuldum.com · 2021-10-25 19:40

Does your blog have a contact page? I’m having problems
locating it but, I’d like to send you an e-mail.

I’ve got some ideas for your blog you might be interested in hearing.
Either way, great blog and I look forward to seeing it expand over time.

my blog post :: http://cozumubuldum.com

Rosalina · 2021-10-25 19:41

I’m not that much of a online reader to be honest but your
sites really nice, keep it up! I’ll go ahead and bookmark your site
to come back down the road. Cheers

cannabis seeds starts · 2021-10-25 19:56

Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates.
I’ve been looking for a plug-in like this for quite some time and was
hoping maybe you would have some experience with something like this.

Please let me know if you run into anything. I truly enjoy reading
your blog and I look forward to your new updates.

Also visit my web-site – cannabis seeds starts

hemp oil · 2021-10-25 19:58

I am really glad to glance at this blog posts which carries lots of helpful information, thanks for providing
such data.

Also visit my web blog: hemp oil

healthy foods · 2021-10-25 20:22

Hi colleagues, how is everything, and what you wish for to say about this article, in my view its actually remarkable for me.

Feel free to visit my site :: healthy foods

Hector · 2021-10-25 20:57

If some one desires expert view regarding blogging after that
i recommend him/her to go to see this webpage,
Keep up the pleasant work.

email marketing · 2021-10-25 20:59

Excellent article. I will be experiencing some of these issues as
well..

Here is my web page email marketing

https://casualvalueinvestor.com/ · 2021-10-25 21:30

Hi my family member! I want to say that this article is amazing, great written and include almost all important infos.
I would like to peer more posts like this .

Feel free to surf to my site – https://casualvalueinvestor.com/

weight loss tips · 2021-10-25 21:38

It’s awesome to visit this web page and reading the views of all colleagues concerning this article, while I am also eager of getting experience.

Here is my webpage weight loss tips

cunnilingus tips · 2021-10-25 22:02

Right here is the right blog for anybody who wants to understand
this topic. You realize so much its almost hard to argue with
you (not that I personally will need to…HaHa). You certainly put a brand new spin on a subject that’s
been written about for years. Excellent stuff, just great!

Look into my webpage – cunnilingus tips

Ahmad · 2021-10-25 22:19

Thank you for the good writeup. It in fact was a amusement account it.
Look advanced to more added agreeable from you! However, how could we communicate?

Harry · 2021-10-25 22:31

I take pleasure in, cause I discovered just what I used to be
having a look for. You’ve ended my four day long hunt!
God Bless you man. Have a great day. Bye

Feel free to surf to my blog post Harry

Jesse · 2021-10-25 22:55

Hello, I enjoy reading all of your article post.
I like to write a little comment to support you.

viewers asmr · 2021-10-25 23:00

Wow, amazing blog structure! How lengthy have you ever
been blogging for? you make running a blog glance easy.
The total look of your website is fantastic, let alone the content material!

my webpage – viewers asmr

cadets.wycombeaircadets.org · 2021-10-25 23:24

I need to to thank you for this excellent read!! I certainly enjoyed every little bit of it.
I’ve got you saved as a favorite to check out new stuff you post?

my webpage; cadets.wycombeaircadets.org

http://www.costidell.com/ · 2021-10-25 23:27

Incredible! This blog looks exactly like my old one!

It’s on a entirely different topic but it has pretty much the same page layout and design. Wonderful choice of colors!

Take a look at my web site; http://www.costidell.com/

www.meteoritegarden.com · 2021-10-25 23:51

Hmm it seems like your site ate my first comment (it was
super long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your
blog. I too am an aspiring blog writer but I’m still new to the whole thing.
Do you have any recommendations for inexperienced blog
writers? I’d really appreciate it.

Also visit my homepage … http://www.meteoritegarden.com

Patti · 2021-10-26 00:01

Magnificent goods from you, man. I have understand your stuff previous to and you are just too great.
I actually like what you’ve acquired here, really like what you
are stating and the way in which you say it.
You make it enjoyable and you still care for to keep it sensible.
I can not wait to read far more from you. This is actually a tremendous site.

forum.vkmoravia.cz · 2021-10-26 00:32

I think this internet site has some really fantastic info for everyone :
D.

Review my blog post; forum.vkmoravia.cz

healthy weight loss · 2021-10-26 00:40

Whoah this weblog is excellent i really like reading your articles.
Keep up the good paintings! You already know, lots of
individuals are looking around for this info, you could aid them
greatly.

my web-site … healthy weight loss

heal eczema · 2021-10-26 00:51

Hello this is somewhat of off topic but I was wondering if blogs
use WYSIWYG editors or if you have to manually code with HTML.

I’m starting a blog soon but have no coding expertise so I wanted to get
advice from someone with experience. Any help would be
greatly appreciated!

My web-site; heal eczema

carb cycling diet · 2021-10-26 01:33

Hello there! This blog post couldn?t be written any better!
Looking at this post reminds me of my previous roommate!
He continually kept preaching about this. I most certainly will forward this information to him.
Pretty sure he’s going to have a very good read.
Many thanks for sharing!

my web-site :: carb cycling diet

best skin care · 2021-10-26 01:48

Thanks for finally writing about > Port Forwarding Using iptables – H'
s Blog best skin care

Robyn · 2021-10-26 02:08

No matter if some one searches for his necessary thing, thus he/she desires to be available
that in detail, thus that thing is maintained over here.

www.aniene.net · 2021-10-26 02:17

I gotta bookmark this website it seems very beneficial invaluable.

Take a look at my homepage :: http://www.aniene.net

treatment process · 2021-10-26 02:42

Write more, thats all I have to say. Literally,
it seems as though you relied on the video to make your point.
You clearly know what youre talking about, why throw away your intelligence on just
posting videos to your weblog when you could be giving us something enlightening to read?

My web site: treatment process

Kristina · 2021-10-26 03:01

I am not very superb with English but I line up this really leisurely to read.

Feel free to surf to my blog: Kristina

weed indoorshave · 2021-10-26 03:15

Wow! This can be one particular of the most beneficial
blogs We’ve ever arrive across on this subject.
Basically Magnificent. I am also an expert in this topic therefore I can understand
your hard work.

Feel free to surf to my site; weed indoorshave

cannabis doctor · 2021-10-26 03:25

Does your blog have a contact page? I’m having a tough time locating it but, I’d like to send
you an email. I’ve got some suggestions for your blog you might be interested in hearing.

Either way, great site and I look forward to seeing it improve
over time.

Also visit my web-site – cannabis doctor

glowing skin · 2021-10-26 03:30

What’s up, everything is going sound here and ofcourse every one is sharing
information, that’s really fine, keep up writing.

Stop by my web page glowing skin

pure hemp seed oil · 2021-10-26 03:39

I would like to convey my affection for your kindness in support
of women who really need help on that concern. Your
very own commitment to getting the solution around became extremely informative and has without exception enabled regular people just like me to achieve their aims.

Your valuable guide can mean so much to me and especially to my colleagues.

Regards; from all of us.

my web page pure hemp seed oil

natural skin care · 2021-10-26 03:51

My spouse and I stumbled over here different website and thought
I might check things out. I like what I see so now i’m
following you. Look forward to going over your web page yet again.

my web page natural skin care

infrared propane heater · 2021-10-26 04:35

I could not refrain from commenting. Perfectly written!

my website :: infrared propane heater

mainsevents.com · 2021-10-26 04:37

Hello, you used to write wonderful, but the last several posts have
been kinda boring… I miss your super writings.
Past few posts are just a bit out of track! come on!

Here is my blog :: mainsevents.com

produce healthy · 2021-10-26 04:39

That is a good tip particularly to those fresh to the blogosphere.
Simple but very accurate info? Thank you for sharing this one.
A must read article!

my blog post produce healthy

http://www.meteoritegarden.com/userinfo.php?uid=3446468 · 2021-10-26 04:46

Marvelous, what a website it is! This blog gives useful data to us, keep it up.

Also visit my homepage http://www.meteoritegarden.com/userinfo.php?uid=3446468

there ps4 games · 2021-10-26 05:20

Greetings from Ohio! I’m bored at work so I
decided to browse your site on my iphone during lunch break.
I enjoy the info you provide here and can’t wait to take
a look when I get home. I’m shocked at how quick your blog loaded on my
cell phone .. I’m not even using WIFI, just 3G .. Anyhow, wonderful blog!

답글 남기기

Avatar placeholder

이메일 주소는 공개되지 않습니다. 필수 항목은 *(으)로 표시합니다