VitualBox6.0.8 - Ubuntu 16.04 Network

1.Network

1.1 网络地址转换(NAT)(内网其他主机不能访问虚拟机ip

1.2 Bridged Adapter(网桥模式:内网其他主机访问虚拟机 IP) Network Configuration

选择 VBox 的虚拟机并设置其网络网卡配置:

连接方式:桥接网卡

界面名称:需要选择你桥接到哪个网卡驱动,我的是无线WLAN的。

 

In Desktop

1. 启动虚拟机,然后设置本机静态 IP 和 桥接的无线网卡的网关:

2. DNS 配置:

sudo gedit /etc/network/interfaces

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
dns-nameservers 8.8.8.8

 3. 重启。Ping 内网主机 IP 和 DNS 如下即成功。

 

In Server

1. 启动虚拟机,然后设置本机静态 IP 、 桥接的无线网卡的网关 和 DNS:

sudo vim /etc/network/interfaces

Below is the original content in file if you r server is auto ip now:

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

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto enp0s3
iface enp0s3inet dhcp

Update the file content for static IP as below:

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

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto enp0s3
iface enp0s3 inet static
address 192.168.1.20
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8

Then reboot ubuntu, the ubuntu can ping link outside network.

 

1.3 Host-Only(内网其他主机不能访问虚拟机ip) Network Configuration

Reference:

https://blog.csdn.net/dkfajsldfsdfsd/article/details/79441874?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task

*Default  IP, getway and DNS

1.2.1 In desktop

ianguo@ianguo-VirtualBox:~$ sudo route add default gw 192.168.137.1
[sudo] password for ianguo: 
ianguo@ianguo-VirtualBox:~$ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.137.1   0.0.0.0         UG    100    0        0 enp0s3
link-local      *               255.255.0.0     U     1000   0        0 enp0s3
192.168.137.0   *               255.255.255.0   U     100    0        0 enp0s3

 配置永久DNS(与网桥方式DNS配置一样)

 

In Server

sudo vim /etc/network/interfaces

Below is the original content in file if you r server is auto ip now:

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

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto enp0s3
iface enp0s3inet dhcp

Update the file content for static IP as below:

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

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto enp0s3
iface enp0s3 inet static
address 192.168.137.5
netmask 255.255.255.0
gateway 192.168.137.1
dns-nameservers 8.8.8.8

Then reboot ubuntu, the ubuntu can ping link outside network.

 

2. Update Software Source Mirror of Ubuntu

1.aliyun softsource

Reference: https://blog.csdn.net/jianzhuan2824/article/details/89298726

run command:

#backup original source configuration
sudo cp /etc/apt/sources.list /etc/apt/sources_init.list

#edit source configuration file now
sudo gedit /etc/apt/sources.list 或者 sudo vim /etc/apt/sources.list

Delete all original configurations, then replace with below new aliyun config:

# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse

Reboot.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值