# KVM, NAT, ssh into VM

## Tanktalus

I've got this setup with VirtualBox, but I'd like to try getting it to work with KVM instead, partly just to get rid of Oracle  :Smile:  and partly just to learn more about KVM.

I run a VirtualBox VM which has another distro of Linux in it.  Once it starts up, I can ssh into it (-p 2222, though it's on port 22 in the VM, and should only work from localhost) and run X apps through that ssh tunnel.  The applications running in the VM have access to my real machine's VPN since it's using NAT.

So I've managed to get QEMU/KVM running the same VirtualBox disk image.  If I ssh from that image to a machine behind the VPN, it seems to work using vde/slirpvde (but ping doesn't work?).  However, I haven't yet figured out how to allow my real machine to ssh into the VM.

I'd also like to be able to expose my DNS server on my main machine to the VM, but without exposing it to any other machines on the network (since no other machine has access to the VPN, and that DNS server handles redirections to the internal network behind the VPN).  If I can't get that to work, I'll just have the VM only use the VPN DNS (this works now), so it's not critical.

Any advice would be appreciated.

----------

## Hu

Please post the command line you use to start the VM.

----------

## Tanktalus

Not much to it.  I think this means it gets to use 2 CPUs (I have 4) and 1GB RAM (also not an issue, I have 12GB).

```
qemu-kvm -net vde -net nic,macaddr=00:00:00:00:00:01 -smp 2 -m 1024 *.vdi
```

----------

## toralf

I'm using a TAP device :

```
qemu-kvm --name foo -m 2047 -hda ~/virtual/kvm/foo.img -cdrom ~/Downloads/tails-i386.iso -boot d -smp 2 -net nic,vlan=0,model=virtio -net tap,vlan=0,ifname=tap3,script=no,downscript=no -vga qxl -spice port=5930,disable-ticketing
```

to start a KVM image on my host, then I'm able to ssh from the guest to my host.

The TAP device I created via gentoo's way :

```
# /etc/conf.d/net

#

#       KVM

#

bridge_br0="tap0 tap1 tap2 tap3"

config_br0="192.168.0.254/16" 

brctl_br0="setfd 0

sethello 10

stp off"

rc_net_br0_need="net.tap0 net.tap1 net.tap2 net.tap3"

config_tap0="null"

tuntap_tap0="tap"

tunctl_tap0="-u tfoerste"

...

#       LAN

#

config_eth0="null"

```

----------

