cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Observer
Observer
533 Views
Registered: ‎09-27-2018

DNS with static ip Petalinux 2019.1

Jump to solution

Hi,

I'm trying to understand how to get the DNS working in Petalinux 2019.1 (Zynq 7030) when using a static IP. By default it uses DHCP, but allows the user to configure a static IP address, by modifying /etc/network/interfaces. This works fine, except for the DNS. Adding nameservers entries to this config file does nothing:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
        address 192.x.y.z
        broadcast 192.x.y.255
        netmask 255.255.255.0
        gateway 192.x.y.z
        # this
        dns-nameservers 8.8.8.8 8.8.4.4
        # or this:
        dns-nameserver 8.8.8.8
# or this
dns-nameservers 8.8.8.8 8.8.4.4
# or this
dns-nameserver 8.8.8.8
# doesn't do anything

Also I can modify resolv.conf, which works, but only for as long as the OS is running. After restart this is cleared. I can see /etc/resolv.conf is actually symbolically linked to /var/run/resolv.conf. Why this is I'm not sure. I'm also not sure what application overwrites this file.

So my question is, how can I add a DNS server in a persistent way in a Petalinux 2019.1 distribution

I've looked at the following resources, but they do not solve this issue:

https://forums.xilinx.com/t5/Embedded-Linux/DNS-not-working-with-static-IP/m-p/868543#M26982

https://unix.stackexchange.com/questions/323446/file-etc-resolv-conf-deleted-on-every-reboot-why-or-what

Thanks!

Cheers,
Vincent

0 Kudos
1 Solution

Accepted Solutions
Highlighted
Observer
Observer
434 Views
Registered: ‎09-27-2018

Re: DNS with static ip Petalinux 2019.1

Jump to solution

Ok, so the problem is as follows: Petalinux 2019.1 maps the resolv.conf into RAM FS. Normally udhcpd would fill this file with whatever comes from the dhcp server. However, when using a static IP, this is not the case.

The fix I made works as follows. Each time ifup is run a scriipt checks whether or not the resolv.conf file is empty. If so it copies the content of resolve.conf.static into this file.

I turned this in a yocto file as follows:

File: <petalinux_root>/project-spec/meta-user/recipes-core/base-files/base_files_%.bbappend

 

FILESEXTRAPATHS_prepend := "${THISDIR}/files:"

SRC_URI += " \
        file://001fixdns \
        "
RDEPENDS_${PN} += "bash"

do_install_append() {
    install -d ${D}${sysconfdir}/network/if-up.d
    install -m 0755 ${WORKDIR}/001fixdns ${D}${sysconfdir}/network/if-up.d
}

File: <petalinux_root>/project-spec/meta-user/recipes-core/base-files/files/001fixdns

 

 

#!/bin/bash

if [ ! -s /etc/resolv.conf ] && [ -f /etc/resolv.conf.static ]
then
        cat /etc/resolv.conf.static > /etc/resolv.conf
fi

Its the best I could come up with. If there are any better suggestions I'm still open to them!

Cheers,
Vincent

 

View solution in original post

0 Kudos
1 Reply
Highlighted
Observer
Observer
435 Views
Registered: ‎09-27-2018

Re: DNS with static ip Petalinux 2019.1

Jump to solution

Ok, so the problem is as follows: Petalinux 2019.1 maps the resolv.conf into RAM FS. Normally udhcpd would fill this file with whatever comes from the dhcp server. However, when using a static IP, this is not the case.

The fix I made works as follows. Each time ifup is run a scriipt checks whether or not the resolv.conf file is empty. If so it copies the content of resolve.conf.static into this file.

I turned this in a yocto file as follows:

File: <petalinux_root>/project-spec/meta-user/recipes-core/base-files/base_files_%.bbappend

 

FILESEXTRAPATHS_prepend := "${THISDIR}/files:"

SRC_URI += " \
        file://001fixdns \
        "
RDEPENDS_${PN} += "bash"

do_install_append() {
    install -d ${D}${sysconfdir}/network/if-up.d
    install -m 0755 ${WORKDIR}/001fixdns ${D}${sysconfdir}/network/if-up.d
}

File: <petalinux_root>/project-spec/meta-user/recipes-core/base-files/files/001fixdns

 

 

#!/bin/bash

if [ ! -s /etc/resolv.conf ] && [ -f /etc/resolv.conf.static ]
then
        cat /etc/resolv.conf.static > /etc/resolv.conf
fi

Its the best I could come up with. If there are any better suggestions I'm still open to them!

Cheers,
Vincent

 

View solution in original post

0 Kudos