目前已经搭建好了ubuntu容器,但是如果想要在本机通过ip访问容器端口服务,不能直接ping通

ubuntu ifconfig

root@c0035d371ca4:~# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.0.2  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:ac:11:00:02  txqueuelen 0  (Ethernet)
        RX packets 12217  bytes 14753141 (14.7 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4665  bytes 535270 (535.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

window 执行:

C:\Windows\system32>route -p add 172.17.0.0 MASK 255.255.255.0 10.0.75.2
 操作完成!

C:\Windows\system32>ping 172.17.0.2

正在 Ping 172.17.0.2 具有 32 字节的数据:
来自 172.17.0.2 的回复: 字节=32 时间<1ms TTL=63
来自 172.17.0.2 的回复: 字节=32 时间<1ms TTL=63
来自 172.17.0.2 的回复: 字节=32 时间<1ms TTL=63

172.17.0.2 的 Ping 统计信息:
    数据包: 已发送 = 3,已接收 = 3,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
    最短 = 0ms,最长 = 0ms,平均 = 0ms
Control-C
^C

这时,windows可以通过172.17.0.2访问容器

其他命令:

  • 查看路由表
C:\Windows\system32>route print
===========================================================================
接口列表
 20...68 f7 28 ee cc c5 ......Realtek PCIe GBE Family Controller
  2...a6 15 d1 b6 3e 52 ......Hyper-V Virtual Ethernet Adapter
 65...00 15 5d 65 ef 08 ......Hyper-V Virtual Ethernet Adapter #2
 11...36 68 95 ac dc b5 ......Microsoft Wi-Fi Direct Virtual Adapter
 17...36 68 95 ac d4 b5 ......Microsoft Wi-Fi Direct Virtual Adapter #2
 26...34 68 95 ac dc b5 ......Microsoft Hosted Network Virtual Adapter
 22...00 50 56 c0 00 01 ......VMware Virtual Ethernet Adapter for VMnet1
 18...00 50 56 c0 00 08 ......VMware Virtual Ethernet Adapter for VMnet8
 21...00 ff cd 68 6b 36 ......TAP-Windows Adapter V9
 23...34 68 95 ac dc b5 ......Broadcom 802.11ac Network Adapter
 25...00 ff e1 68 37 72 ......TeamViewer VPN Adapter
 15...34 68 95 ac dc b6 ......Bluetooth Device (Personal Area Network)
  1...........................Software Loopback Interface 1
===========================================================================

IPv4 路由表
===========================================================================
活动路由:
网络目标        网络掩码          网关       接口   跃点数
          0.0.0.0          0.0.0.0      192.168.1.1     192.168.1.57     45
        10.0.75.0    255.255.255.0            在链路上         10.0.75.1    271
        10.0.75.1  255.255.255.255            在链路上         10.0.75.1    271
      10.0.75.255  255.255.255.255            在链路上         10.0.75.1    271
        127.0.0.0        255.0.0.0            在链路上         127.0.0.1    331
        127.0.0.1  255.255.255.255            在链路上         127.0.0.1    331
  127.255.255.255  255.255.255.255            在链路上         127.0.0.1    331
      169.254.0.0      255.255.0.0            在链路上    169.254.166.60    291
      169.254.0.0      255.255.0.0            在链路上   169.254.165.210    291
  169.254.165.210  255.255.255.255            在链路上   169.254.165.210    291
   169.254.166.60  255.255.255.255            在链路上    169.254.166.60    291
  169.254.255.255  255.255.255.255            在链路上    169.254.166.60    291
  169.254.255.255  255.255.255.255            在链路上   169.254.165.210    291
   172.26.248.112  255.255.255.240            在链路上    172.26.248.113    271
   172.26.248.113  255.255.255.255            在链路上    172.26.248.113    271
  • 删除路由
C:\Windows\system32>route delete 172.17.0.2

参考:https://www.cnblogs.com/brock0624/p/9788710.html

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐