参考:
https://blog.csdn.net/zgf19930504/article/details/51955067
原文链接:https://www.f2er.com/ubuntu/349614.html1 先使用ifconfig查看网卡名称
$ ifconfig ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.3.39 netmask 255.255.255.0 broadcast 192.168.3.255 inet6 fe80::279b:4479:ea46:ae99 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:ee:4b:bc txqueuelen 1000 (Ethernet) RX packets 44187 bytes 21079541 (21.0 MB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 29266 bytes 9993375 (9.9 MB) 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 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 810 bytes 71857 (71.8 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 810 bytes 71857 (71.8 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
我的网卡名称为ens33.
2 修改文件添加网卡
修改文件/etc/network/interfaces,添加网卡,网卡名为:原来网卡(ens33):1,可以创建多个,修改:后面的数字即可。
$ sudo vim /etc/network/interfaces原始内容为:
# interfaces(5) file used by ifup(8) and ifdown(8) auto lo iface lo inet loopback改为:
# interfaces(5) file used by ifup(8) and ifdown(8) auto lo iface lo inet loopback auto ens33:1 iface ens33:1 inet static address 123.1.0.123 netmask 255.255.255.0
3 使用ifconfig查看结果
$ sudo /etc/init.d/networking restart $ ifconfig ens33: flags=4163<UP,MULTICAST> mtu 1500 inet 192.168.3.39 netmask 255.255.255.0 broadcast 192.168.3.255 inet6 fe80::279b:4479:ea46:ae99 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:ee:4b:bc txqueuelen 1000 (Ethernet) RX packets 44442 bytes 21113893 (21.1 MB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 29484 bytes 10015338 (10.0 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ens33:1: flags=4163<UP,MULTICAST> mtu 1500 inet 123.1.0.123 netmask 255.255.255.0 broadcast 123.1.0.255 ether 00:0c:29:ee:4b:bc txqueuelen 1000 (Ethernet) lo: flags=73<UP,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 870 bytes 76225 (76.2 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 870 bytes 76225 (76.2 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
4 访问123.1.0.123,查看是否可以访问
先用Ubuntu访问http://123.1.0.123,确定是可以访问到内容的
Android设备未连接VPN的情况下访问http://123.1.0.123,访问不通
Android设备连接VPN后访问http://123.1.0.123,可以成功访问
PS:在这里我是先安装了apache(sudo apt-get install apache2 apache2-doc),访问http://123.1.0.123和访问http://127.0.0.1的效果相同。