mikma / lxd-openwrt

Scripts for building LXD images from OpenWrt rootfs tarballs.
MIT License
150 stars 39 forks source link

Need to add default uci LAN IP configuration on eth0 during image creation #3

Closed KathrynMorgan closed 5 years ago

KathrynMorgan commented 5 years ago

Thanks for this work. I have built a container image and uploaded it to my personal (public) image server.

I have not yet been able to launch an instance and get an IP on the LAN iface.

I would gladly assist in writing the readme/wiki for a PR with help determining the steps required.

KathrynMorgan commented 5 years ago

solved that xenial hosts work fine, bionic hosts are not allowing this to work properly. Will pursue in containerforums

niklashagman commented 5 years ago

Hi KathrynMorgan Am defining everything in network file before compiling the image. I am then placing this config in builddir/files/etc/config/network file. You have probably also discovered this so what are you missing? :-)

KathrynMorgan commented 5 years ago

I came back around to it and noticed the lan IP 192.168.1.1 was getting created but then lost within seconds of container startup.

Manually adding it back via ip addr add 192.168.1.1/24 dev br-lan brought back all expected functionality.

After stumbling across that I havent stopped to investigate further yet.

EDIT: Just watched the container startup more closely.

The lan IP is handed to the eth0 interface. The br-lan bridge is created a few moments into container startup. Once the br-lan bridge interface is created the eth0 interface loses its IP which would seem logical. However, the IP does not get provisioned on the br-lan interface. Provisioning this IP manually solves the issue.

niklashagman commented 5 years ago

aha, I see. I can see that the author has changed how network is started since I pulled the latest from git. The change is in 0c5ad68128d49fec8b8770c343f30360c91c1b81. Before it was written in files/etc/config/network but now days uci commands are used. Okay.. well..okay :-) I now get what you are asking about. Would be nice to easily understand how I can prime my container image. Before it was to put files in files/etc/config/ and it would end up on the host in /etc/config directory.

KathrynMorgan commented 5 years ago

Below is my network file as well as my ip config. remember the LAN IP is added manually right now :/

/etc/config/network

root@gw:~# cat /etc/config/network 
config interface 'loopback'
    option ifname 'lo'
    option proto 'static'
    option ipaddr '127.0.0.1'
    option netmask '255.0.0.0'

config globals 'globals'
    option ula_prefix 'fd31:811f:3a9a::/48'

config interface 'lan'
    option type 'bridge'
    option ifname 'eth0'
    option proto 'dhcp'

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

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

ip a s

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: br-lan: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
    link/ether 00:16:3e:81:d6:6f brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.1/24 scope global br-lan
       valid_lft forever preferred_lft forever
    inet6 fe80::216:3eff:fe81:d66f/64 scope link 
       valid_lft forever preferred_lft forever
20: eth0@if21: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue master br-lan state UP qlen 1000
    link/ether 00:16:3e:81:d6:6f brd ff:ff:ff:ff:ff:ff
22: eth1@if23: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP qlen 1000
    link/ether 00:16:3e:fc:3f:0b brd ff:ff:ff:ff:ff:ff
    inet 172.1.0.116/24 brd 172.1.0.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::216:3eff:fefc:3f0b/64 scope link 
       valid_lft forever preferred_lft forever
KathrynMorgan commented 5 years ago

Okay, Troubleshooting. Before & After uci config. Following: https://openwrt.org/docs/guide-user/base-system/basic-networking

I was able to restart the container and the IP configuration is all working correctly now after these commands:

root@gw:~# uci set network.lan.ipaddr='192.168.1.1'
root@gw:~# uci set network.lan.netmask='255.255.255.0'
root@gw:~# uci set network.lan.proto='static'
root@gw:~# uci commit

BEFORE:

root@gw:~# uci show network
network.loopback=interface
network.loopback.ifname='lo'
network.loopback.proto='static'
network.loopback.ipaddr='127.0.0.1'
network.loopback.netmask='255.0.0.0'
network.globals=globals
network.globals.ula_prefix='fd31:811f:3a9a::/48'
network.lan=interface
network.lan.type='bridge'
network.lan.ifname='eth0'
network.lan.proto='dhcp'
network.wan=interface
network.wan.ifname='eth1'
network.wan.proto='dhcp'
network.wan6=interface
network.wan6.ifname='eth1'
network.wan6.proto='dhcpv6'

AFTER:

root@gw:~# uci show network
network.loopback=interface
network.loopback.ifname='lo'
network.loopback.proto='static'
network.loopback.ipaddr='127.0.0.1'
network.loopback.netmask='255.0.0.0'
network.globals=globals
network.globals.ula_prefix='fd31:811f:3a9a::/48'
network.lan=interface
network.lan.type='bridge'
network.lan.ifname='eth0'
network.lan.netmask='255.255.255.0'
network.lan.ipaddr='192.168.1.1'
network.lan.proto='static'
network.wan=interface
network.wan.ifname='eth1'
network.wan.proto='dhcp'
network.wan6=interface
network.wan6.ifname='eth1'
network.wan6.proto='dhcpv6'
KathrynMorgan commented 5 years ago

Now just need to build on the syntax in files/etc/board.d/99-default_network to set those 3 variables I guess?

niklashagman commented 5 years ago

Yeah, it seems to be that easy. Just cp in your own files/etc/board.d/99-default_network before the build.

KathrynMorgan commented 5 years ago

Marking solved.

Removed 'dhcp' from end of line 13 in file files/etc/board.d/99-default_network to re-enable typical static 192.168.1.1 ip behavior on lan br/eth0