Setting DNS with static IP config



  • Hi,

    I'm trying to use static IP for the Omega2, last firmware 0.2.0 (b194).
    All works fine, except DNS setting.

    This is my /etc/config/network file config:

    config interface 'wwan'
            option ifname 'apcli0'
            option proto 'static'
            option hostname 'Omega'
            option ipaddr '192.168.1.95'
            option netmask '255.255.255.0'
            option gateway '192.168.1.1'
            option dns '8.8.8.8'
    

    After network config restart with command /etc/init.d/network restart, I try to ping to google with:

    root@Omega # ping google.com
     ping: bad address 'google.com'
    

    It can't resolve hostnames with static IP configuration. If I use DHCP config, no problem.

    My ifconfig output:

    apcli0    Link encap:Ethernet  HWaddr 40:A3:6B:C1:44:0E
              inet addr:192.168.1.95  Bcast:192.168.1.255  Mask:255.255.255.0
              inet6 addr: fe80::42a3:6bff:fec1:440e/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:0 errors:0 dropped:0 overruns:0 frame:0
              TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
    

    Anybody use static IP? Can share configuration files?.

    Thanks in advance!



  • Hi

    i work in DHCP but with a static lease with the MAC Address of apcli0 (xxxxx0E for you but not the MAC Address of the Omega Label )

    my router is a Mikrotik and this system work for all IOT (ESP 8266 / ESP 32 / 4Duino ...)

    Bye



  • @Jean-Eudes-Quidet-0 said in Setting DNS with static IP config:

    Hi

    i work in DHCP but with a static lease with the MAC Address of apcli0 (xxxxx0E for you but not the MAC Address of the Omega Label )

    my router is a Mikrotik and this system work for all IOT (ESP 8266 / ESP 32 / 4Duino ...)

    Bye

    Hi, It's no apply in this case, because I'm finding a solution without modify router setup.



  • Maybe the dnsmasq program interferes? What does /etc/resolv.conf say?



  • @Maximilian-Gerhardt said in Setting DNS with static IP config:

    Maybe the dnsmasq program interferes? What does /etc/resolv.conf say?

    Maybe... I try all configurations in /etc/config/network and /etc/config/dhcp, but it doesn't work.

    File /etc/resolv.conf is modified by dnsmasq after boot.



  • Well, I think is a problem of routing tables:

    Output of route -n command with DHCP (default device config):

    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 apcli0
    192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 apcli0
    192.168.1.1     0.0.0.0         255.255.255.255 UH    0      0        0 apcli0
    192.168.3.0     0.0.0.0         255.255.255.0   U     0      0        0 br-wlan
    

    With STATIC IP config:

    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 apcli0
    192.168.3.0     0.0.0.0         255.255.255.0   U     0      0        0 br-wlan
    

    So, I route manually with command:
    # route add default gw 192.168.1.1

    And voila, ping google.com works...


    Complete config for static IP

    Device IP address 192.168.1.95 and router/gateway in 192.168.1.1.

    Modify interface 'wwan' in file /etc/config/network as follow:

    config interface 'wwan'
            option ifname 'apcli0'
            option proto 'static'
            option hostname 'Omega-XXXX'
            option ipaddr '192.168.1.95'
            option netmask '255.255.255.0'
            option gateway '192.168.1.1'
            option dns '8.8.8.8'
    

    If you use the Access Point (example a phone connected to Omega as Wi-Fi client) add DNS servers to /etc/dnsmasq.conf file:

    # Use public DNS servers for Access Point when
    # static IP is used for 'wwan' interface.
    
    server=8.8.8.8
    server=8.8.4.4
    

    Add these commands to /etc/rc.local to update config on next boot:

    # ----------------------------------------------------------
    # COMMANDS FOR STATIC IP CONFIG
    # ----------------------------------------------------------
    
    # Add routing table (need it for STATIC IP config)
    route add default gw 192.168.1.1
    
    # Restart Dnsmasq for update DNS servers (only Access Point)
    /etc/init.d/dnsmasq restart
    

    Next, reboot Omega.

    Check if the route -n has a similar output:

    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 apcli0
    192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 apcli0
    192.168.3.0     0.0.0.0         255.255.255.0   U     0      0        0 br-wlan
    

    And ofcourse, try ping google.com command.

    Conclusion

    In my humilde opinion there are a config bug for static IP, maybe Onion would fix it.

    References:

    [https://wiki.openwrt.org/doc/howto/dhcp.dnsmasq](link url)

    [https://wiki.openwrt.org/doc/uci/routing_in_ipv4](link url)

    [https://wiki.openwrt.org/doc/uci/network](link url)

    [https://www.techrepublic.com/article/configure-it-quick-use-the-route-command-to-set-up-routing-tables-on-linux/](link url)


Log in to reply
 

Looks like your connection to Community was lost, please wait while we try to reconnect.