虚拟机是怎么和外部网络通信的?

系统安装、升级讨论
版面规则
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
回复
头像
xwp911
帖子: 137
注册时间: 2013-01-13 21:26
系统: ubuntu14.04

虚拟机是怎么和外部网络通信的?

#1

帖子 xwp911 » 2015-10-14 11:30

我的防火墙设置如下:
Status: active
日志: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
新建配置文件: skip

至 动作 来自
- -- --
22/tcp ALLOW IN Anywhere
139/tcp ALLOW IN Anywhere
445/tcp ALLOW IN Anywhere
22/tcp (v6) ALLOW IN Anywhere (v6)
139/tcp (v6) ALLOW IN Anywhere (v6)
445/tcp (v6) ALLOW IN Anywhere (v6)
在虚拟机中的网络连接情况情况如下:
Proto Local Address Foreign Address State
TCP 0.0.0.0:135 0.0.0.0:0 LISTENING
TCP 0.0.0.0:445 0.0.0.0:0 LISTENING
TCP 10.0.2.15:139 0.0.0.0:0 LISTENING
TCP 10.0.2.15:3466 106.120.74.85:7709 ESTABLISHED
TCP 10.0.2.15:3492 61.135.149.187:80 ESTABLISHED
UDP 0.0.0.0:445 *:*
UDP 0.0.0.0:1026 *:*
UDP 10.0.2.15:137 *:*
UDP 10.0.2.15:138 *:*
UDP 127.0.0.1:3438 *:*
请大神们指教!
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: 虚拟机是怎么和外部网络通信的?

#2

帖子 poloshiao » 2015-10-14 12:46

安裝虛擬機時
網卡類別選哪一種 ?

補充
ufw 對於 out 一律放行不管制
头像
xwp911
帖子: 137
注册时间: 2013-01-13 21:26
系统: ubuntu14.04

Re: 虚拟机是怎么和外部网络通信的?

#3

帖子 xwp911 » 2015-10-14 15:06

poloshiao 写了:安裝虛擬機時
網卡類別選哪一種 ?
有NAT的,也有桥接的,都能。
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: 虚拟机是怎么和外部网络通信的?

#4

帖子 poloshiao » 2015-10-14 16:18

有NAT的,也有桥接的,都能。
都能
指能完成什麼任務 ?
头像
xwp911
帖子: 137
注册时间: 2013-01-13 21:26
系统: ubuntu14.04

Re: 虚拟机是怎么和外部网络通信的?

#5

帖子 xwp911 » 2015-10-14 20:07

使用虚拟黑群晖,或者迅雷,或者炒股软件等等
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: 虚拟机是怎么和外部网络通信的?

#6

帖子 poloshiao » 2015-10-14 21:25

有NAT的,也有桥接的,都能。
NAT 應該沒問題
橋接 需要再求證

ufw 是管制 進來 不管制 出去 的連接請求
头像
xwp911
帖子: 137
注册时间: 2013-01-13 21:26
系统: ubuntu14.04

Re: 虚拟机是怎么和外部网络通信的?

#7

帖子 xwp911 » 2015-10-15 9:26

NAT 應該沒問題
ufw 是管制 進來 不管制 出去 的連接請求
为什么防火墙管不住虚拟机

为什么你说NAT就可以啊?明明防火墙的设置是如下的:
Status: active
日志: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
新建配置文件: skip

至 动作 来自
- -- --
22/tcp ALLOW IN Anywhere
139/tcp ALLOW IN Anywhere
445/tcp ALLOW IN Anywhere
22/tcp (v6) ALLOW IN Anywhere (v6)
139/tcp (v6) ALLOW IN Anywhere (v6)
445/tcp (v6) ALLOW IN Anywhere (v6)
只开了这几个端口的outgoing啊??? 有些晕

再者,桥接再次确认也可以啊。

是否我的防火墙没起作用
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: 虚拟机是怎么和外部网络通信的?

#8

帖子 poloshiao » 2015-10-15 11:17

明明防火墙的设置是如下的
如果你說的防火牆 ufw 是安裝在 Guest
那麼 ufw 預設規則 就是只管理 Imcoming 不管理 Outgoing
如果你要連 Outgoing 也納入管理 請使用 iptables
https://help.ubuntu.com/community/IptablesHowTo

補充
https://help.ubuntu.com/community/Firewall#UFW
UFW (Uncomplicated Firewall) is a front-end for iptables
ufw 是 Iptables 的前端程式
意思是 使用 ufw 實際上背後執行的也是 Iptables
头像
xwp911
帖子: 137
注册时间: 2013-01-13 21:26
系统: ubuntu14.04

Re: 虚拟机是怎么和外部网络通信的?

#9

帖子 xwp911 » 2015-10-22 11:52

我的防火墙是安装在真实的主机上的,系统ubuntu14.04。虚拟机是xp,目前就是上述的情况。并且,在主机上运行teamviewer也是畅通无阻的,不知为什么?
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: 虚拟机是怎么和外部网络通信的?

#10

帖子 poloshiao » 2015-10-22 12:01

虚拟机是xp
XP 的網卡是 NAT ? 如果是
你的 XP 好像是一個獨立的 PC
意思是 Host 的防火牆並不能保護 Guest
需要在 XP 另外安裝/設定 防火牆

https://www.virtualbox.org/manual/UserManual.html
13.3.2 Secure Configuration of Virtual Machines
13.3.2.1 Networking
The default networking mode for VMs is NAT which means that the VM acts like a computer
behind a router, see chapter 6.3, Network Address Translation (NAT), page 97. The guest is part
of a private subnet belonging to this VM and the guest IP is not visible from the outside. This
networking mode works without any additional setup and is sufficient for many purposes.
头像
xwp911
帖子: 137
注册时间: 2013-01-13 21:26
系统: ubuntu14.04

Re: 虚拟机是怎么和外部网络通信的?

#11

帖子 xwp911 » 2015-10-22 12:09

我有2个XP虚拟机,一个XP的网卡是NAT,一个是桥接,都畅通无阻。很奇怪。
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: 虚拟机是怎么和外部网络通信的?

#12

帖子 poloshiao » 2015-10-22 12:43

一个是桥接
橋接 你的 XP 網卡 就好像 Host Ubuntu 一樣
所以受到 Host Ubuntu 防火牆的保護

https://www.virtualbox.org/manual/ch13. ... 9064383968
If bridged networking is used, the VM acts like a computer inside the same network as the host, see Section 6.5, “Bridged networking”. In this case, the guest has the same network access as the host and a firewall might be necessary to protect other computers on the subnet from a potential malicious guest as well as to protect the guest from a direct access from other computers. In some cases it is worth considering using a forwarding rule for a specific port in NAT mode instead of using bridged networking.
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: 虚拟机是怎么和外部网络通信的?

#13

帖子 poloshiao » 2015-10-22 12:52

都畅通无阻
兩個 XP 防火牆 分開討論
比較不會混淆
回复