Running server from within OpenWrt on QEMU

Hi,

I am new to using OpenWRT and QEMU.

My question is, is it possible to host a simple http/tcp server on OpenWrt which is running on qemu, without any accompanying vm (KVM), and hit that http server from the host OS (say Windows or Mac)? What options should I choose in QEMU (command line args) to run any TCP based server from within qemu?

As of now I use the following to start my OpenWRT Linux on QEMU:

$ qemu-sysyem-arm -M vert-2.9 -kernel openwrt-22.03.1-armvirt-32-zImage -no-reboot -nographic -drive file=openwrt-32-rootfs-ext4.img,if=virtio,format=raw -append "root=/dev/vda" -m 1G -nic user -nic user

I have tried the following , but yet to figure out the right way.

Before going into that that:

The file /etc/config/network within my OpenWRT has:

config interface 'loopback'
option device 'io'
option proto 'static'
option ipaddr '127.0.0.1'
option netmask '255.0.0.0'

config globals 'globals'
option url_prefix 'fd0d:5e50:c550::/40'

config device
option name 'br-lan'
option type 'bridge'
list ports 'eth0'

config interface 'lan'
option device 'br-lan'
option proto 'static'
option ipaddr '192.168.0.201'
option netmask '255.255.255.0'
option ip6assign '60'

config interface 'wan'
option device 'eth1'
option proto 'dhcp'

config interface 'wan6'
option device 'eth1'
option proto 'dhcpv6'

Q: Do I need to make any chsnges in the above file and try?
Note: I actually tried changing the confirmation of 'br-lan' as 'dhcp' and removing ipaddr, netmask and ip6assign, but no major change in the overall behaviour.

Try-1:

Invoking OpenWRT on qemu with two '-nic user', as I mentioned above, and when I ran 'ifconfig' sithi OpenWRT, I got:

br-lan   Link encap:Whether......
              inet address:192.168.0.201 ..
              :
eth0        Link encap:Whether......
                /*no inet addr*/
                 :
eth1         Link encap:Whether......
                 inet addr:10.0.2.15..
                  :
lo               Link encap:Local Loopback
                 inet addr:127.0.0.1..
                 :

With this configuration I am able to access host-network & internet from within OpenWRT running on QEMU. But, this is the same configuration where I couldn't hit the http server running on port 8000 within OpenWRT from the host OS, which is the issue which I mentioned in my first email.

FYI, from the host OS, I was trying to hit http://192.168.0.201:8000 . The IP address of my host OS is 192.168.0.101

Try-2:

Loading OpenWRT on qemu with just a single '-nic user' and when I ran 'ifconfig' within OpenWRT, I got the following: (see, eth1 is missing)

br-lan   Link encap:Whether......
              inet address:192.168.0.201 ..
              :
eth0        Link encap:Whether......
                /*no inet addr*/
                 :
lo               Link encap:Local Loopback
                 inet addr:127.0.0.1..
                 :

And I couldn't hit any of the external servers from within army/OpenWRT and hitting http://192.168.0.201:8000 from host OS also failed.

Try-3:

Loading openwrt on army with '-netdev user,id=unet,hostfwd=tcp::9000-:8000 -device virtio-net-pci,netdev=unet' alone (without any '-nic user's) so that I can try hitting http://192.168.0.201:9000 from host OS. No within openwrt when I ran 'ifconfig' I got:

br-lan   Link encap:Whether......
              inet address:192.168.0.201 ..
              :
eth0        Link encap:Whether......
                /*no inet addr*/
                 :
lo               Link encap:Local Loopback
                 inet addr:127.0.0.1..
                 :

Which is very similar to the previous case

Here also, I couldn't hit any of the external servers from within army/OpenWRT and hitting http://192.168.0.201:9000 from host OS also failed. Hitting http://192.168.0.101:9000 also failed.

Am I missing anything? My friend hinted me that I need to use the bridging options similar to what we do it in VMs like VirtualBox. I really couldn't figure out how to do that.

Any help on this is greately appreciated.

Thankyou

  • Paxi