How to skip pushing the default gateway via DHCP in OpenWRT?

2

3

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.

francadaval

Posted 2013-05-15T21:40:06.197

Reputation: 121

2

0.0.0.0 != NULL. See http://en.wikipedia.org/wiki/0.0.0.0 :)

– Ƭᴇcʜιᴇ007 – 2013-05-15T22:10:52.417

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. – Frank Thomas – 2013-05-15T22:55:16.583

1Frank, 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. – francadaval – 2013-05-16T07:36:40.687

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 – 2014-03-06T22:07:42.280

Answers

9

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

Daniel B

Posted 2013-05-15T21:40:06.197

Reputation: 40 502

0

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' 
    ...

MrMas

Posted 2013-05-15T21:40:06.197

Reputation: 133

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.

Tonny

Posted 2013-05-15T21:40:06.197

Reputation: 19 919

By not supplying the option I get the same default gateway. – francadaval – 2013-05-15T22:05:51.763

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.

Nevin Williams

Posted 2013-05-15T21:40:06.197

Reputation: 3 725

1If 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? – francadaval – 2013-05-16T07:32:54.630

Am I to understand you have two routers...? – Nevin Williams – 2013-05-16T07:39:33.067

1Yes. I have a router conected to Internet and other one just for a local network. – francadaval – 2013-05-16T08:18:23.347

So you have two networks; Are you trying to serve both networks with one router's DHCP server? – Nevin Williams – 2013-05-16T09:41:19.580

1No, 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. – francadaval – 2013-05-16T10:02:22.823

What IP address/netmask would you want a wifi host to have, and what IP address/netmask would you want a wired host to have? – Nevin Williams – 2013-05-16T16:12:28.657

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.

Art Shayderov

Posted 2013-05-15T21:40:06.197

Reputation: 280

You have a point about setting this up on the client, but the question is about the gateway, not the DNS server. – Nicolas Marchildon – 2015-07-01T03:22:50.737