Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

networking is not working on qemu guest (Malta Mips)

I am trying to configure networking on QEMU malta mips, which is running on vmware host (ubuntu) using tap/tun device and bridge interface. My qemu guest is unable to retrieve ip address from DHCP server. If i give it manually, it can just connect with its host. Using tcpdump i came to know that outgoing traffic is working perfectly but incoming is not working.

Can anyone suggest me how to solve this kind of issue? Thank You

like image 749
marry Avatar asked Feb 01 '14 09:02

marry


1 Answers

If you use NAT mode, then your host machine will act as a router for your guest VM. This means you must enable routing on your host.

Assuming you start qemu and link it to tap0 interface and your outgoing internet interface is eth0, then you should:

  1. Create the tap0 virtual interface:

    tunctl -t tap0
    ifconfig tap0 192.168.0.1 netmask 255.255.255.0 up
    
  2. Activate routing

    # activate ip forwarding
    echo 1 > /proc/sys/net/ipv4/ip_forward
    
    # Create forwarding rules, where
    # tap0 - virtual interface
    # eth0 - net connected interface
    
    iptables -A FORWARD -i tap0 -o eth0 -j ACCEPT
    iptables -A FORWARD -i eth0 -o tap0 -m state --state ESTABLISHED,RELATED -j ACCEPT
    iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
    
  3. Start your VM with somenthing like this:

    qemu [..] -net nic,model=e1000,vlan=0 -net tap,ifname=tap0,vlan=0,script=no
    
  4. In your VM, configure an interface with ip 192.168.0.2/24 and default gateway 192.168.0.1

like image 139
catalin.me Avatar answered Sep 30 '22 08:09

catalin.me