[공유기] - ipTIME
192.168.0.1
[컴퓨터1] - Linux
192.168.0.2
255.255.255.0
192.168.0.1
[컴퓨터2] - 192.168.10.* 망 게이트웨이 Linux
(랜카드1)
192.168.0.3
255.255.255.0
192.168.0.1
(랜카드2)
192.168.10.1
255.255.255.0
(게이트 웨이 미지정)
[컴퓨터3] - Linux
192.168.10.2
255.255.255.0
192.168.10.1
이런 상황인데, 컴퓨터1 에서 컴퓨터3 로 SSH 접속을 하려고 합니다.
그런데, 접속이 안되는데 아무래도 서브넷 마스크를 잘못 준거 때문이 아닐까 싶은데
위 각각의 서브넷 마스크를 어떻게 수정해야 이런 형태의 접속이 가능할까요 ?
컴퓨터1, 컴퓨터2-랜카드1, 컴퓨터2-랜카드2, 컴퓨터3 으로 지정해서 알려주시면 쉽게 이해될것 같습니다.
[root@192.168.0.2 ~]# ssh 192.168.10.2 22
ssh: connect to host 192.168.10.2 port 22: Connection timed out
고맙습니다.
ps) 댓글을 보고 공유기에 라우팅 설정하니 ping 은 들어갑니다
2. ÄÄÇ»ÅÍ 2ÀÇ iptables¿¡¼ forward table default policy¸¦ ACCEPT·Î ¼³Á¤
IP ¸¦ ÇØ´ç ÄÄÇ»ÅÍ IP ·Î Á¤È®ÇÏ°Ô ÁöÁ¤ÇÏ°í ½Í¾î¿ä
ÄÄÇ»ÅÍ1ÀÇ GWÀº 192.168.0.1À̹ǷÎ, 192.168.0.1¿¡¼ ¶ó¿ìÆÃÀ» ÇØÁà¾ß 192.168.10.0/24 ´ë¿ªÀ¸·Î ³Ñ¾î°¥ ¼ö ÀÖ½À´Ï´Ù.
ÇÏÁö¸¸ iptime °øÀ¯±â¿¡ 192.168.10.0/24 ´ë¿ªÀÇ IPµµ ¾øÀ¸¸ç ¶ó¿ìÆà ¼³Á¤µµ ¾ÈµÇ¾î ÀÖÀ¸¹Ç·Î, ÄÄÇ»ÅÍ 1¿¡¼ 3À¸·Î ³×Æ®¿öÅ© ´ë¿ªÀº Á¢±ÙÇÒ ¼ö ¾ø´Â °ÍÀÌ ¸Â½À´Ï´Ù.
ÄÄÇ»ÅÍ 1°ú 3À» Åë½ÅÇÏ°í ½ÍÀ¸½Ã´Ù¸é
1. ÄÄÇ»ÅÍ 1¿¡ 192.168.10.0/24 ´ë¿ªÀ» ¸¸µé¾î Áֽðųª (´ÙÁß IP)
2. 192.168.0.0/22 ´ë¿ªÀ¸·Î ³×Æ®¿öÅ© ´ë¿ªÀ» ´Ã·ÁÁֽðųª
3. ÄÄÇ»ÅÍ 2¸¦ GW·Î ¸¸µé¾î¼ 192.168.10.0/24 ´ë¿ªÀ» ¶ó¿ìÆÃÇϵµ·Ï Çϸé (IPTIME °øÀ¯±â Á¦¿Ü)
°¡´ÉÇϸ®¶ó »ý°¢ÇÕ´Ï´Ù.
À§ÀÇ °¡Á¤µéÀº Àû¾îµµ ¸ðµç ȸ¼±ÀÌ L2·Î ´Ù ¿¬°áµÇ¾î ÀÖ´Ù´Â °ÍÀ» ÀüÁ¦·Î ÇÕ´Ï´Ù.
±×·±µ¥ ¿Ö ÀÌ·± ³×Æ®¿öÅ© ±¸¼ºÀ» ÇÒ·Á°í ÇϽô °Ç°¡¿ä? ÄÄÇ»ÅÍ 3´ë¿¡ ´Ü¼ø ´ë¿ª ³ª´®Àº Å« Àǹ̰¡ ¾øÀ» °Í °°Àºµ¥¿ä..
192.168.10.* ´ë¿ªÀº °¡»óÈ ¼¹ö¶ó °Ô½ºÆ®µéÀÌ ¸¹ÀÌ ÀÖ½À´Ï´Ù. 192.168.0.* À¸·Î Àâ¾Æ³õÀ¸¸é ÀÌ ¼¹ö¸¦ »ç¹«½Ç À̵¿ÇßÀ»¶§ ±×°÷ÀÇ 192.168.0.* ¸Á°ú Ãæµ¹Çϱ⠶§¹®¿¡ ÀÌ·¸°Ô ÇÑ°ÍÀÔ´Ï´Ù.
1. ÄÄÇ»ÅÍ 1¿¡ 192.168.10.0/24 ´ë¿ªÀ» ¸¸µé¾î Áֽðųª (´ÙÁß IP) -> ¼ö½Ê´ëÀÇ ¸ðµç ÄÄÇ»ÅÍ ¸¶´Ù ÀÌ·¸°Ô Ãß°¡ ÇÒ¼ö°¡ ¾øÀ¸´Ï ÀÌ ¹æ¹ýÀº ¾ÈµÉ°Í °°½À´Ï´Ù.
2. 192.168.0.0/22 ´ë¿ªÀ¸·Î ³×Æ®¿öÅ© ´ë¿ªÀ» ´Ã·ÁÁֽðųª -> ÀÌ°Ç ¾î¶»°Ô ÇÒ ¼ö ÀÖ³ª¿ä ? ¼ºê³Ý ¸¶½ºÅ©¸¦ 255.255.0.0 À¸·Î ÁÖ¸é µÇ´Â°ÍÀΰ¡¿ä ?
3. ÄÄÇ»ÅÍ 2¸¦ GW·Î ¸¸µé¾î¼ 192.168.10.0/24 ´ë¿ªÀ» ¶ó¿ìÆÃÇϵµ·Ï Çϸé (IPTIME °øÀ¯±â Á¦¿Ü) -> ÄÄÇ»ÅÍ2´Â ÀÌ¹Ì GWÀÔ´Ï´Ù. ÄÄÇ»ÅÍ2¿¡µµ ¶ó¿ìÆà ¼³Á¤À» Ãß°¡Ç϶ó´Â ¾ê±âÀΰ¡¿ä ? ¾î¶²½ÄÀ¸·Î ÇÒ ¼ö ÀÖÀ»±î¿ä ? (±¸Ã¼ÀûÀÎ ¸í·É¾î...)
À§¿¡ Ãß°¡ÇÑ »çÁøó·³ °øÀ¯±â ¶ó¿ìÆà ¼³Á¤À» Ãß°¡ÇÏ´Ï ÄÄÇ»ÅÍ 1¿¡¼ ÄÄÇ»ÅÍ 3 À¸·Î ping ÀÌ µÇ±â ½ÃÀÛÇϴµ¥, ¾ÆÁ÷ ssh ¿¬°áÀº ¾ÈµË´Ï´Ù. ¹» ´õ ÇØÁà¾ß ÇÒ±î¿ä ?
IPtime °øÀ¯±â¿¡ ¶ó¿ìÆà ³Ö¾îÁּžßÇÕ´Ï´Ù
192.168.10.0/24 -> 192.168.0.3
±×¸®°í ¸Þ½ÃÁö°¡ ¾Æ·¡¿Í °°ÀÌ ¹Ù²î¾ú´Âµ¥, ¹º°¡ Çϳª¸¦ ´õ ÇØÁà¾ß ÇÏ´Â °Í °°½À´Ï´Ù. ¹» ´õ ÇØÁà¾ß ÇÒ±î¿ä ?
(ÀÌÀü) - ping ¾ÈµÊ
[root@webcom ~]# ssh user1@192.168.10.2 -p 22
ssh: connect to host 192.168.10.2 port 22: Connection timed out
(ÀÌÈÄ) °øÀ¯±â ¶ó¿ìÆà ¼³Á¤ÈÄ - ping µÊ
[root@webcom ~]# ssh user1@192.168.10.2 -p 22
ssh: connect to host 192.168.10.2 port 22: No route to host
ÄÄ2¿¡¼ sysctl -a |grep ip_forward Çϼż ÇØ´ç °ªÀÌ 1·Î ¼ÂÆõǾîÀÖ´ÂÁö È®ÀÎÇÏ½Ã°í ¾ÈµÇ¾îÀÖÀ¸¸é
vi /etc/sysctl.conf
net.ipv4.ip_forward=1
³ÖÀ¸½Ã°í
sysctl -p
ÇϽøé Àû¿ë µË´Ï´Ù.
net.ipv4.ip_forward = 1
net.ipv4.ip_forward_usr_pmtu = 0
ÀÌ·¸°Ô Çϸé Àß µÇ¾î ÀÖ´Â °ÍÀΰ¡¿ä ? Àú´Â µû·Î º¯°æÇÑ °ÍÀº ¾ø½À´Ï´Ù...
¿©ÀüÈ÷ ¾ÈµÇ°í Àֳ׿ä
[root@webcom log]# ping 192.168.10.2
PING 192.168.10.2 (192.168.10.2) 56(84) bytes of data.
64 bytes from 192.168.10.2: icmp_seq=1 ttl=63 time=1.24 ms
From 192.168.0.1 icmp_seq=2 Redirect Host(New nexthop: 192.168.0.3)
64 bytes from 192.168.10.2: icmp_seq=2 ttl=63 time=1.03 ms
From 192.168.0.1 icmp_seq=3 Redirect Host(New nexthop: 192.168.0.3)
64 bytes from 192.168.10.2: icmp_seq=3 ttl=63 time=0.998 ms
^C
--- 192.168.10.2 ping statistics ---
3 packets transmitted, 3 received, +2 errors, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 0.998/1.087/1.235/0.105 ms
[root@webcom log]# ssh 192.168.10.2 -p 22
ssh: connect to host 192.168.10.2 port 22: No route to host
ÄÄ1¿¡¼ ÄÄ3À¸·Î ping Àº µÇ´Âµ¥ ssh°¡ ¾ÈµË´Ï´Ù...
¹Ý¸í, ÄÄ3¿¡¼ ÄÄ1·Î´Â pingµµ µÇ°í, sshµµ ¿¬°áµË´Ï´Ù.
ÀÌ°Ô Âü ÀÌ»óÇÑ Á¡À̳׿ä...
Ȥ½Ã ¸ô¶ó¼ ÄÄ3¿¡¼ vi /etc/hosts.allow
sshd: 192.168.
ÀߵǾî ÀÖ½À´Ï´Ù. ¸·Èù°Íµµ ¾Æ´Õ´Ï´Ù.
±×¸®°í 192.168.10.* ¸ÁÀÇ ´Ù¸¥ ÄÄÇ»ÅÍ¿¡¼´Â 192.168.10.2 ·Î ssh°¡ Àß ºÙ½À´Ï´Ù.
¿øÀÎÆľÇÀ» À§Çؼ ÆÐŶµ¢ÇÁ¸¦ ¶°º¼ ÇÊ¿ä°¡ ÀÖÀ»°Í°°½À´Ï´Ù
tcpdump ¸í·É¾î¸¦ »ç¿ëÇÏ¿© ÄÄÇ»ÅÍ2°¡ Á߰踦 Àß ÇØÁÖ´ÂÁö, ÄÄÇ»ÅÍ3±îÁö ÆÐŶÀÌ µµ´ÞÇÏ´ÂÁö üũÇغ¸¼¼¿ä
1. ÄÄÇ»ÅÍ2
#tcpdump -nni ·£Ä«µå1ÀÎÅÍÆäÀ̽º¸í host 192.168.0.2
»óÅ¿¡¼ ÄÄ1 -> ÄÄ3:22 ½ÃµµÇغ¸¼¼¿ä
2. ÄÄÇ»ÅÍ2
#tcpdump -nni ·£Ä«µå2ÀÎÅÍÆäÀ̽º¸í host 192.168.0.2
»óÅ¿¡¼ ÄÄ1 -> ÄÄ3:22 ½ÃµµÇغ¸¼¼¿ä
3. ÄÄÇ»ÅÍ3
#tcpdump -nni ·£Ä«µåÀÎÅÍÆäÀ̽º¸í host 192.168.0.2
»óÅ¿¡¼ ÄÄ1 -> ÄÄ3:22 ½ÃµµÇغ¸¼¼¿ä
À§ 3°¡Áö¸¦ Çغ¸½Ã¸é ¾îµð°¡ ¸·È÷´ÂÁö ¾Ë ¼ö ÀÖ½À´Ï´Ù
±× °á°ú¸¦ Åä´ë·Î Á¶Ä¡¸¦ ÇÏ½Ã´Â°Ô ¸ÂÀ» °Í °°½À´Ï´Ù
# tcpdump -nni ens160 host 192.168.0.2
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens160, link-type EN10MB (Ethernet), capture size 262144 bytes
03:28:03.490732 IP 192.168.0.2.54946 > 192.168.10.2.10122: Flags [S], seq 2881666181, win 64240, options [mss 1460,sackOK,TS val 509379747 ecr 0,nop,wscale 7], length 0
03:28:03.490787 IP 192.168.0.4 > 192.168.0.2: ICMP host 192.168.10.2 unreachable - admin prohibited, length 68
03:28:08.508213 ARP, Request who-has 192.168.0.2 tell 192.168.0.4, length 28
03:28:08.508621 ARP, Reply 192.168.0.2 is-at 18:c0:4d:46:74:58, length 46
# tcpdump -nni ens192 host 192.168.0.2
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens192, link-type EN10MB (Ethernet), capture size 262144 bytes
# tcpdump -nni ens160 host 192.168.0.2
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens160, link-type EN10MB (Ethernet), capture size 262144 bytes
±×·³ À§ ·Î±×¿¡¼ ¾îµð°¡ ¹®Á¦Àΰɱî¿ä ?
vi /etc/sysctl.conf
net.ipv4.conf.default.rp_filter=2
net.ipv4.conf.all.rp_filter=2
sysctl -p
sysctl: cannot stat /proc/sys/net/ipv4/conf/app/rp_flter: ±×·± ÆÄÀÏÀ̳ª µð·ºÅ͸®°¡ ¾ø½À´Ï´Ù
# sysctl -p
net.ipv4.conf.default.rp_filter = 2
net.ipv4.conf.all.rp_filter = 2
ÄÄ1¿¡¼ ÄÄ3 ssh ¿¬°á½Ãµµ
# ssh 192.168.10.2 -p 10122
ssh: connect to host 192.168.10.2 port 10122: No route to host
¿©ÀüÈ÷ ¾ÈµÇ°í Àֳ׿ä. ÀÏ´Ü ¼³Á¤Àº ¹éÇß½À´Ï´Ù...
¿©±â´Ù ´ñ±Û µå¸³´Ï´Ù
ÄÄÇ»ÅÍ2¿¡ ¹æȺ®ÀÌ ¿Ã¶ó°¡ÀÖ´Â°Í °°³×¿ä
iptables ÀÏ°Í°°Àºµ¥
iptablesÀ̵ç firewallÀ̵ç È®ÀÎÇϼż
ÄÄ1 -> ÄÄ3:22 ¹æȺ® Á¤Ã¥À»
ÄÄ2¿¡ ³Ö¾îÁּžßÇÕ´Ï´Ù
±×·±µ¥ ¹æȺ®ÀÌ ÄÑÁ®À־ ÄÄ3¿¡¼ ÄÄ1·Î ssh´Â µÆ¾ú´Âµ¥ ÀÌ°Ç ¹«°üÇÑ°Ç°¡ º¸³×¿ä?
±×·±µ¥, ÄÄ2´Â ÀÎÅÍ³Ý ¸Á¿¡ ³ëÃâµÉ¼öµµ Àְŵç¿ä. 192.168.0.3(4) °¡ Áö±ÝÀº ¼ºê³ÝÀÌÁö¸¸ ·ºÀ» À̵¿ÇÏ¸ç °øÀÎIP°¡ ¼³Á¤µÉ¼öµµ ÀÖ½À´Ï´Ù.
±×·¡¼ ÄÄ2´Â SSH ·Î Á¢±Ù ºÒ°¡´ÉÇÕ´Ï´Ù. ±×·±µ¥, Á¦°¡ ¿øÇÏ´Â°Ç ÄÄ2·Î SSH¸¦ Çã¿ëÇؼ ÄÄ2¿¡ SSH¸¦ ºÙ´Â°Ô ¾Æ´Ï¶ó ´ÜÁö °ÔÀÌÆ®¿þÀ̸¦ Åë°úÇؼ ÄÄ1->ÄÄ3À¸·Î ssh¸¦ ºÙ´Â°Çµ¥¿ä
±×·³ ÀÌ°æ¿ì ÄÄ2 ¹æȺ®¿¡ ¾î¶² ¸í·É¾î¸¦ Áà¾ß ³»ºÎ ¼ºê³ÝÀ¸·Î ssh Á¢±ÙÀÌ µÉ±î¿ä ? CentOS ÀÔ´Ï´Ù
ps) Æ÷Æ® Æ÷¿öµùÀ» °É¾îÁÖ´Ï±î µÇ±äÇϴµ¥... ±×·±µ¥ Á¦°¡ ¿øÇÏ´Â °ÍÀº ƯÁ¤ Æ÷Æ®¿¡ ´ëÇØ Æ¯Á¤ IP·Î °¡¶ó´Â Æ÷Æ® Æ÷¿öµùÀÌ ¾Æ´Ñ, °¡·É 22¹ø Æ÷Æ®´Â ¾î¶² ÄÄÇ»Å͵çÁö °®À»¼ö Àִµ¥... ƯÁ¤ Æ÷Æ®¸¦ ƯÁ¤ ÄÄÇ»ÅͷΠƯÁ¤ÇÏ°í ½ÍÁö ¾Ê°Åµç¿ä. ±×·³ ÀÌÁ¦ ¾î´ÀÁ¤µµ ¿øÀÎÀ» ¾Ë¾ÒÀ¸´Ï... ÀÌÁ¤µµ¿¡¼ ¸¶¹«¸®ÇÏ°í ÇÊ¿äÇÏ¸é ´Ù½Ã Áú¹®À» ¿Ã·Á¾ß°Ú³×¿ä. ¸ðµÎ °í¸¿½À´Ï´Ù.
iptables¶ó¸é
Forward Á¤Ã¥¿¡
ÄÄ1 -> ÄÄ3:22 tcp Á¤Ã¥À» ³Ö¾îÁÖ¾î¾ß°ÚÁÒ