Home>

You can ping outside from centOS

[root @ 7971df01d10c /] # ping google.com
PING google.com (172.217.161.46) 56 (84) bytes of data.
64 bytes from nrt12s23-in-f14.1e100.net (172.217.161.46): icmp_seq = 1 ttl = 37 time = 36.2 ms
64 bytes from nrt12s23-in-f14.1e100.net (172.217.161.46): icmp_seq = 2 ttl = 37 time = 59.0 ms
64 bytes from nrt12s23-in-f14.1e100.net (172.217.161.46): icmp_seq = 3 ttl = 37 time = 29.0 ms
64 bytes from nrt12s23-in-f14.1e100.net (172.217.161.46): icmp_seq = 4 ttl = 37 time = 717 ms
64 bytes from nrt12s23-in-f14.1e100.net (172.217.161.46): icmp_seq = 5 ttl = 37 time = 60.6 ms


You can also ping locally

[root @ 7971df01d10c /] # ping 172.17.0.2
PING 172.17.0.2 (172.17.0.2) 56 (84) bytes of data.
64 bytes from 172.17.0.2: icmp_seq = 1 ttl = 64 time = 0.043 ms
64 bytes from 172.17.0.2: icmp_seq = 2 ttl = 64 time = 0.062 ms
64 bytes from 172.17.0.2: icmp_seq = 3 ttl = 64 time = 0.062 ms
64 bytes from 172.17.0.2: icmp_seq = 4 ttl = 64 time = 0.042 ms
64 bytes from 172.17.0.2: icmp_seq = 5 ttl = 64 time = 0.062 ms
64 bytes from 172.17.0.2: icmp_seq = 6 ttl = 64 time = 0.063 ms


It looks like this when you hit ip a

[root @ 7971df01d10c /] # ip a
1: lo:<LOOPBACK, UP, LOWER_UP>mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00: 00: 00: 00: 00: 00 brd 00: 00: 00: 00: 00: 00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: tunl0 @ NONE:<NOARP>mtu 1480 qdisc noop state DOWN group default qlen 1
    link/ipip 0.0.0.0 brd 0.0.0.0
3: ip6tnl0 @ NONE:<NOARP>mtu 1452 qdisc noop state DOWN group default qlen 1
    link/tunnel6 :: brd ::
6: eth0 @ if7:<BROADCAST, MULTICAST, UP, LOWER_UP>mtu 1500 qdisc noqueue state UP group default
    link/ether 02: 42: ac: 11: 00: 02 brd ff: ff: ff: ff: ff: ff link-netnsid 0
    inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
       valid_lft forever preferred_lft forever


When you try to connect ssh from outside, it looks like this

ssh: connect to host 172.17.0.2 port 22: Network is unreachable


Ping from outside

ping 172.17.0.2
PING 172.17.0.2 (172.17.0.2): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
36 bytes from 60.47.170.89: Destination Host Unreachable
Vr HL TOS Len ID Flg off TTL Pro cks Src Dst
 4 5 00 5400 46e1 0 0000 3c 01 7c24 10.13.204.27 172.17.0.2
  • Answer # 1

    When connecting from the host to the container, the port will be forwarded, so the destination IP should be 127.0.0.1 instead of 172.17.0.2.

    Reference
    I tried to build a development environment with Docker for Mac. did. Another reason is that the IP address was not set with the "nmtui" command.

    In the first place, the purpose of SSH connection was that it was necessary to create one server as a team.

    I'm sorry for the delay. The question became unclear when I was a beginner of server construction and I didn't know what to do. I'm sorry for the inconvenience to the respondents. Thank you for your answer.

  • Answer # 2

    Hmm, where should I explain?
    Assumes that the following conditions are met:

    172.217.161.46 is the host OS address where Docker is running.

    You can log in to 172.217.161.46 from the Internet side with ssh.

    Ssh is set appropriately on the Docker side (running or key pair is set properly)

    Raise Docker with port fowarding enabled

    First, start SSH (TCP/21) running on the Docker container to port forward to an appropriate port of the host OS (eg TCP/7021).

    $docker run --name hogehoge -d -p 7021: 21 containar_name
    Create an ssh tunnel from the Internet environment to 172.217.161.46
    $ssh -L 9999: localhost: 7021 172.217.161.46
    For the tunnel just created ssh
    $ssh -p 9999 localhost

    There is no relationship between ping and ssh.
    Please read appropriately per address.
    Since 172.17.0.2 is a private address, it has no meaning outside the LAN.

    Hmm, Docker is not related at all.