Hyper-v虚拟机下Ubuntu Server 14.04 配置网络

来源:互联网 发布:win2008端口转发 编辑:程序博客网 时间:2024/05/17 20:51

Hyper-v中设置

1. 进入虚拟交换机管理器

2. 新建网络虚拟交换机,连接类型为外部网络,选择一块网卡

(我是买了一块USB网卡用于虚拟机上网,主板自带的网卡用于物理机上网)

3. 设置虚拟机的网络适配器为刚刚新建的虚拟交换机

4. 启动虚拟机


Ubuntu Server 设置

1. 检查是否启用 Hyper-V IC module

lsmod|grep hv_vmbus

如果启用会有以下显示

hv_vmbus 65536 7 hv_balloon,hyperv_keyboard,hv_netvsc,hid_hyperv,hv_utils,hyperv_fb,hv_storvsc


2. 如果没有,可能你的Ubuntu版本较低,需要编辑/etc/initramfs-tools/modules

vi /etc/initramfs-tools/modules在之后追加hv_vmbushv_storvschv_blkvschv_netvsc追加后保存按ESC键:wq保存后,运行update-initramfs,并reboot系统sudo update-initramfs –usudo reboot

3. 配置网卡IP地址,vi /etc/network/interfaces,添加以下代码

静态地址方式(推荐)

#根据你的实际网路环境设置auto eth0 iface eth0 inet staticaddress 192.168.1.122 netmask 255.255.255.0network 192.168.1.0broadcast 192.168.1.255gateway 192.168.1.1dns-nameservers 8.8.8.8

动态地址方式
auto eth0iface eth0 inet dhcp


4. 设置DNS,vi /etc/resolv.conf,添加

nameserver 8.8.8.8


5. 生效

sudo /etc/init.d/networking restartreboot



6. 测试

ping www.baidu.com或wget http://www.baidu.com


此时可以连接外网,或可以用Filezilla等工具连接Ubuntu (一般都已安装SSH服务)

用Filezilla访问Ubuntu,如果用root帐号,需修改 vi /etc/ssh/sshd_config,否则会出现“认证失败”

找到permitrootlogin:withpassword改成permitrootlogin:yes保存后重启ssh服务service ssh restart