2

I have a router with OpenWRT that I want to resolve IP addressing with DHCP without setting a default gateway.

I have added a DHCP-Option parameter with value 3,0.0.0.0 that is supposed to set the default gateway by DHCP. Instead, the router IP is defined as default gateway for DHCP connections.

How can I set a null default gateway (0.0.0.0) for connections configuration by DHCP?

As said in a comment: I want this router to service a VirtualBox network that doesn't set a default gateway via DHCP.

4
  • 2
    0.0.0.0 != NULL. See en.wikipedia.org/wiki/0.0.0.0 :) May 15, 2013 at 22:10
  • Default gateway is fundamental to the workings of the IP stack, and many internal functions will not work correctly without it. the system WILL infer one, whether correctly or incorrectly for your desired result. May 15, 2013 at 22:55
  • 1
    Frank, I want the system to take the default gateway from other router connected to the Internet. They already have a default gateway but the wrong one is taken. I want this one to do as VirtualBox network that doesn't set a default gateway via DHCP. May 16, 2013 at 7:36
  • Default gateway is set by the DHCP. If the client is on the same subnet than the wanted gateway, then you can use its DHCP server, or set your DHCP to send this gateway. However, it is probably not the case. That's why you've to use your router as a DHCP server and a gateway, with routing rules to route packet from the client's subnet to the wanted gateway's subnet.
    – piernov
    Mar 6, 2014 at 22:07

6 Answers 6

12

Well, the question is already old, but here's the solution. dnsmasq implicitly sets its host as the DNS server and default gateway. To disable this behavior, use the following configuration directives:

  • dhcp-option=3 to disable setting the default gateway
  • dhcp-option=6 to disable setting the DNS server
2

Building off of Daniel B's answer, for OpenWRT, modify /etc/config/dhcp to add the appropriate options:

config dnsmasq
    ...
    # To disable setting the default gateway
    option dhcp_option '3' 

    # To disable setting the DNS server
    option dhcp_option '6' 
    ...
0

By not supplying the option at all ?

Please note that not supplying a default gateway is not going to work on some Operating Systems. Some will automatically assume that the DHCP server is the default gateway if no default gw (or an invalid one. 0.0.0.0 is technically invalid) is specified.
Others will listen for router advertisements send out by the router and get the routers address from that.

1
  • By not supplying the option I get the same default gateway. May 15, 2013 at 22:05
0

Since all other routes will take precedence over default route, then specify the default gateway as localhost (127.0.0.1), which will keep hosts configured via DHCP from working unless they've a more specific route defined.

6
  • 1
    If this roter set de default gateway as localhost and other router set its IP as default gateway (to Internet connection) the last one takes precedence over the other? May 16, 2013 at 7:32
  • Am I to understand you have two routers...? May 16, 2013 at 7:39
  • 1
    Yes. I have a router conected to Internet and other one just for a local network. May 16, 2013 at 8:18
  • So you have two networks; Are you trying to serve both networks with one router's DHCP server? May 16, 2013 at 9:41
  • 1
    No, the main router is for internet connection via wifi (no posibilities to connect to it by cable :-( ) and the other to ensure independent local network connection beetwen computers for home development environment. May 16, 2013 at 10:02
0

You are approaching the task from the wrong end. That kind of configuration should be set on the client side. Don't know what kind of clients do you have. For Debian (Ubuntu) add to

/etc/dhcp/dhclient.conf

the following line

supersede domain-name-servers 8.8.8.8

change 8.8.8.8 (Google Public DNS) to your DNS server.

1
  • You have a point about setting this up on the client, but the question is about the gateway, not the DNS server.
    – Nicolas
    Jul 1, 2015 at 3:22
0

You can always use a small script to delete a default route on a certain interface.

#!/bin/sh
# file /etc/sysconfig/network-scripts/ifup.d/2greet
route del default enp3s0f0

chmod +x /etc/sysconfig/network-scripts/ifup.d/2greet

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.