Ip

查找 VPN 客戶端的本地 IP

  • January 17, 2017

我有兩台伺服器伺服器 A 和伺服器 B。伺服器 B 是伺服器 A 的 VPN。當伺服器 A 在伺服器 B 的 VPN 後面時,如何在伺服器 B 上找到伺服器 A 的本地 IP?我認為當我發出命令“ifconfig”時應該列出它,但我不確定當時我正在尋找哪個 IP。

ifconfig -a 的輸出

gre0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-8C-B9-00-00-00-00-00-00-00-00
         NOARP  MTU:1476  Metric:1
         RX packets:0 errors:0 dropped:0 overruns:0 frame:0
         TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:0
         RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

gretap0   Link encap:Ethernet  HWaddr 00:00:00:00:00:00
         BROADCAST MULTICAST  MTU:1476  Metric:1
         RX packets:0 errors:0 dropped:0 overruns:0 frame:0
         TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:1000
         RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

ip6tnl0   Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
         NOARP  MTU:1460  Metric:1
         RX packets:0 errors:0 dropped:0 overruns:0 frame:0
         TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:0
         RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

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:377 errors:0 dropped:0 overruns:0 frame:0
         TX packets:377 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:0
         RX bytes:76799 (76.7 KB)  TX bytes:76799 (76.7 KB)

tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
         inet addr:10.8.0.1  P-t-P:10.8.0.1  Mask:255.255.255.0
         UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
         RX packets:8726841 errors:0 dropped:0 overruns:0 frame:0
         TX packets:7897879 errors:0 dropped:22138 overruns:0 carrier:0
         collisions:0 txqueuelen:100
         RX bytes:6123986424 (6.1 GB)  TX bytes:6479665617 (6.4 GB)

venet0    Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
         inet addr:127.0.0.2  P-t-P:127.0.0.2  Bcast:0.0.0.0  Mask:255.255.255.255
         inet6 addr: 2604:180:2:127b::2ed4/64 Scope:Global
         UP BROADCAST POINTOPOINT RUNNING NOARP  MTU:1500  Metric:1
         RX packets:18726387 errors:0 dropped:0 overruns:0 frame:0
         TX packets:16971835 errors:0 dropped:799 overruns:0 carrier:0
         collisions:0 txqueuelen:0
         RX bytes:13379179118 (13.3 GB)  TX bytes:13281478025 (13.2 GB)

venet0:0  Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
         inet addr:107.191.96.157  P-t-P:107.191.96.157  Bcast:107.191.96.157  Mask:255.255.255.255
         UP BROADCAST POINTOPOINT RUNNING NOARP  MTU:1500  Metric:1

從標籤來看,我猜你正在執行 OpenVPN。OpenVPN 使用 tun 或 tap 隧道,所以應該是tun0. 然後您的本地 IP(在 VPN 上)是 10.8.0.1,這很奇怪(因為它讓我覺得配置錯誤)也是對等 IP。

BTW:在Linux上,ifconfig(朋友)基本上已經過時了,被ip命令取代了。ip addr ls會給你所有的地址。

引用自:https://unix.stackexchange.com/questions/338125