Ubuntu VM nat模式上网

(一)服务器安装,选择nat模式

(二)打开VMware workstation ,菜单栏选项-->编辑-->虚拟网络编辑器,如图:

注意:上图的子网IP可以自己指定,我这里指定了192.168.1.0,以前是192.168.186.1。由于我家路由器IP为192.168.1.1,家里别的电脑都是1段,所以这里我也指定了1段,我修改为别的段就是不能上网,也不能用xshell连接Ubuntu系统

点击NAT设置可以看到 VMware Network Adapter VMnet8 ,网关为192.168.1.2

注意,等会DNS也配置这个IP

(三)配置服务器IP

vi /etc/network/interfaces

# This file describes the network interfaces available on your system
# and how to activate them. For more information,see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.2

(四)配置DNS

网上有些方法说配置到这里 ,但是重启动dns就没了: /etc/resolv.conf

永久DNS配置方法

vi /etc/resolvconf/resolv.conf.d/base

nameserver 192.168.1.2

注意:这里的DNS就上上面的网关IP

(五)测试

我是把防火墙关闭后测试的:apt-get remove iptables

重启动系统,ping 百度,如下所示:

PING baidu.com (180.149.132.47) 56(84) bytes of data. 64 bytes from 180.149.132.47: icmp_seq=1 ttl=128 time=26.8 ms 64 bytes from 180.149.132.47: icmp_seq=2 ttl=128 time=28.1 ms 64 bytes from 180.149.132.47: icmp_seq=3 ttl=128 time=27.0 ms 64 bytes from 180.149.132.47: icmp_seq=4 ttl=128 time=29.7 ms

相关文章

目录前言一、创建Hadoop用户二、更新apt和安装Vim编辑器三、...
原文连接:https://www.cnblogs.com/yasmi/p/5192694.html ...
电脑重启后,打开VirtualBox,发现一直用的虚拟机莫名的消失...
参见:https://blog.csdn.net/weixin_38883338/article/deta...
Ubuntu 18.04 LTS 已切换到 Netplan 来配置网络接口。Netpla...
介绍每个 Web 服务都可以通过特定的 URL 在 Internet 上访问...