Builds on, or at least modifies, Getting OpenWRT Working in VirtualBox.
This time I set up OpenWRT in VirtualBox with one NIC - Bridged instead of the default NAT. All that was needed to get networking functional was:
# uci set network.lan.ipaddr=172.16.0.37 # uci set network.lan.netmask=255.255.255.0 # uci commit # this updates file /etc/config/network # ifdown lan # ifup lan
Note that this will work if 172.16.0.37 is a legitimate (and unused) address on your local network (and when I say "local," I mean the one your host's network card is attached to). You can even set it to the same IP as the host machine. I have no idea if that's a good idea or a bad one - my knowledge of bridged networking is approximately nil, which is why I'm doing this! But if you use the host machine's IP, you won't be able to access OpenWRT ports from the host or other machines on the network because responses will always come from the host and not the OpenWRT virtual machine.
Not quite there, add /etc/resolv.conf, adding the following lines:
nameserver 172.16.0.1 # your local router or DNS nameserver 220.127.116.11 # Google's public DNS (you shouldn't need this)
Remember to delete /etc/resolv.conf, which is a link to /tmp/resolv.conf, and mv or cp /tmp/resolv.conf to /etc/resolv.conf so the changes are permanent.
You still need routing. Edit /etc/config/network and add this stanza:
config 'route' option interface 'lan' option target '*' option netmask '255.255.255.0' option gateway '172.16.0.1'
(This isn't working for me at the moment: I'll update when fixed.)
Since this virtual machine is now out on the network (ie. not just enclosed in the safe world of your internal network) it's a good idea to change the root password. This does another thing beyond changing root's password: it closes the telnet port, fixing your two most obvious security loopholes.