小编Ben*_*Ben的帖子

Ubuntu上的KVM:端口转发到来宾VM

我安装了kvm并使用vmbuilder在服务器上设置了几个guest.以下是以下配置:

server host1 (xxx.xxx.xxx.xxx) ->  guest vm1 (192.168.122.203)
                               ->  guest vm2 (192.168.122.204)
Run Code Online (Sandbox Code Playgroud)

其中xxx.xxx.xxx.xxx是host1的修复IP地址.

我想使用以下命令连接到vm1:

ssh username@host1 -p 2222
Run Code Online (Sandbox Code Playgroud)

我尝试通过在iptables中添加以下规则来实现:

sudo iptables --table nat --append PREROUTING --protocol tcp --destination xxx.xxx.xxx.xxx --destination-port 2222 --jump DNAT --to-destination 192.168.122.203:22
Run Code Online (Sandbox Code Playgroud)

但是当我跑步时我超时了:

ssh username@host1 -p 2222
Run Code Online (Sandbox Code Playgroud)

这是我的iptables规则:

sudo iptables -nL -v --line-numbers -t nat
Chain PREROUTING (policy ACCEPT 32446 packets, 3695K bytes)
num   pkts bytes target     prot opt in     out     source               destination         
1        7   420 DNAT       tcp  --  *      *       0.0.0.0/0            xxx.xxx.xxx.xxx        tcp dpt:2222 to:192.168.122.203:22

Chain …
Run Code Online (Sandbox Code Playgroud)

ssh redirect kvm ubuntu-12.04

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

kvm ×1

redirect ×1

ssh ×1

ubuntu-12.04 ×1