# dnsmasq server is NOT the gateway

## nic01

Hi all

I'm playing around with dnsmasq on my home network. The problem is how to specify the gateway in the dnsmasq dhcp server. Here is my setup:

Linksys router 10.0.0.1 (the actual gateway)

my server 10.0.0.10     (just connected to the linksys switch)

my clients 10.0.0.* 

When my clients (linux and windows clients) optain a ip address from dnsmasq it routes all external traffic to server (10.0.0.10), where it should route to 10.0.0.1:

```

10.0.0.0        *               255.255.255.0   U     0      0        0 eth0

loopback        localhost       255.0.0.0       UG    0      0        0 lo

default         Server          0.0.0.0         UG    0      0        0 eth0

```

That would of cause be fine if my server was also the gateway.. But it's not. 

Any thoughts?

/nic

----------

## golloza

dnsmasq has an DHCP server?   :Shocked: 

I thought, it's just a small DNS server

----------

## nic01

yep.. a lightweight dhcp server. 

maybe using dhcpd as dhcp server instead could solve my problem. But would dnsmasq be able to read the dhcp.lease file for local name lookup?

/nic

----------

## ptfoof

I looked in RFC2131 and the code for dnsmasq and it doesn't seem that the gateway is something that the DHCP has to give to the client.  I had the same problem and have lived with a static default gateway set in /etc/conf.d/net .  This seems a shame, but your gateway will not be moving it's IP address will it?

----------

## nic01

Well. You're right about setting the router static could do the trick. A bit of a hassle though, especially when you have a mixed linux and windows enviroment.

My solution was to use the 'standard' dhcpd server to handle the asignment of ip adresses  (it of cause let you define a proper gateway). I then changed the dnsmasq lease file to (in /etc/dnsmasq.conf): 

```

dhcp-leasefile=/var/lib/dhcp/dhcpd.leases

```

which works like a charm.

Oh, don't forget to specify the host name on the linux dhcp clients (otherwise it wont be included in the dhcp.leases file) and to set the 

```
 dhcp-option=81
```

 in /etc/dnsmasq.conf .. dnsmasq wouldn't do the local namelookup without that. 

Thanks for the inputs

/Nic

----------

## UberLord

 *nic01 wrote:*   

> 
> 
> ```
>  dhcp-option=81
> ```
> ...

 

I've never heard of option 81 (and a quick goole just shows Win2k errors) and my dnsmasq runs fine without it.

Are you sure you added 127.0.0.1 to /etc/hosts?

----------

## pi314

AFAIR dnsmasq has some options to set the gateway and other things that should be submitted to the clients - if not set it defaults to the box running dnsmasq - maybe you should give those configs a second closer look and read the manpages, or as soon as I'm back at my linux station I'll look for those options

----------

## andrew_j_w

I think you want to add

```

dhcp-option=3,192.168.0.1

```

to /etc/dnsmasq.conf. Obviously replace 192.168.0.1 with the correct address.

HTH,

Andrew

----------

## ptfoof

Option 3 is for the default router.  Is a router the same as a gateway?

----------

## UberLord

 *ptfoof wrote:*   

> Option 3 is for the default router.  Is a router the same as a gateway?

 

Yes

----------

## pi314

ok, the needed dnsmasq options are already posted. But there is something else to be done. The route of the server running dnsmasq must also have the default gatway set

 *Quote:*   

> route add default gw 10.0.0.1

  is AFAIR the command to do this manualy, the config file to set this permanent is /etc/conf.d/net.eth0

Or is there a way to let the dnsmasq server get a dynamic ip via dhcpcd (with dnsmasq and dhcpcd on the same machine, of course)?

----------

