View previous topic :: View next topic |
Author |
Message |
hans_da n00b
Joined: 09 Mar 2007 Posts: 64
|
Posted: Thu Oct 02, 2008 11:44 am Post subject: How to setup a fallback DNS server if DHCP failed |
|
|
The idea is really simple. I would like to have HDCP to detect possible IP address. If not, than use a fallback static IP address. My conf.d/net is as follow:
config_eth0=( "dhcp" )
dhcpcd_eth0="-t 5 -L"
fallback_eth0=( "134.60.14.66 netmask 255.255.255.0 brd 134.60.14.255" )
fallback_route_eth0=( "default via 134.60.14.1" )
However, everytime when I start eth0 the DHCP overwrite the DNS(resolv.conf), no matter whether the DHCP is successful or not. How can I configure a default dns here for eth0, when the DHCP failed?
Thanks! |
|
Back to top |
|
|
mno Guru
Joined: 29 Dec 2003 Posts: 454 Location: Toronto, Canada
|
Posted: Thu Oct 02, 2008 4:07 pm Post subject: |
|
|
What version of dhcpcd are you running? There was a bug in 4.0.1 and you should go to 4.0.2... _________________ "Hello and goodbye. As always." | You can't use here?? | Unanswered |
|
Back to top |
|
|
h017ah n00b
Joined: 18 Apr 2007 Posts: 46
|
Posted: Thu Apr 23, 2009 9:33 am Post subject: |
|
|
Did you find out about this, hand_da? I had to hack around in /lib/dhcpcd/dhcpcd-hooks/20-resolv.conf to make dhcpcd not discard the nameservers set by /etc/init.d/net.eth0, and the solution I came up with is kinda hackish...
I also have a problem with getting fallback_route_eth0="default via <gw>" to work. No matter how I format it, it gets ignored.
Also the notation fallback_eth0="<ip> netmask <netmask> brd <broadcast>" doesn't work, I had to write it in CIDR-notation, e.g. fallback_eth0="192.168.0.1/32"
I'm running openrc-0.4.3-r2 and dhcpcd-4.0.12 |
|
Back to top |
|
|
UberLord Retired Dev
Joined: 18 Sep 2003 Posts: 6835 Location: Blighty
|
|
Back to top |
|
|
h017ah n00b
Joined: 18 Apr 2007 Posts: 46
|
Posted: Thu Apr 23, 2009 8:06 pm Post subject: |
|
|
... for this issue to get resolved this quickly and elegantly, who would have thought? :)
Of course this worked as a charm, UberLord, thanks for letting us know :) Just remember to enable zeroconf, either by setting the use-flag zeroconf when building dhcpcd, or by commenting out "noipv4ll" from dhcpcd.conf.
[Solved] |
|
Back to top |
|
|
maxxim n00b
Joined: 03 Feb 2015 Posts: 27
|
Posted: Tue Feb 03, 2015 9:04 pm Post subject: Fallback for DNS in /etc/conf.d/net |
|
|
Hi there,
I was also trying to find a solution for this for quite a while. My goal was to have an all-in-one-solution using only /etc/conf.d/net.
Here's what I came up with:
Code: | # /etc/conf.d/net
#
# Use DHCP for eth0. DHCP configuration: be quiet, wait 15 seconds
# for a response, disable IP address checking via ARP (faster boot).
#
# In case DHCP fails, the specified fallback configuration is used.
# Note that 'fallback_dns_eth0' is handled by postup() since there
# is no native support for this.
#
# Configure DHCP for eth0
config_eth0="dhcp"
dhcpcd_eth0="--quiet --timeout 15 --noarp"
# Configure fallback for eth0
fallback_eth0="10.10.10.10 netmask 255.255.255.0"
fallback_routes_eth0="default via 10.10.10.254"
fallback_dns_eth0=("10.10.10.254")
# Define postup function for DNS fallback
# (refer to '/usr/share/doc/netifrc-0.2.2/net.example' for details)
function postup {
# Determine if there is a fallback configuration for the given interface
fb_var="fallback_dns_${IFACE}"
fb_arr="fallback_dns_${IFACE}[@]"
if [ -n "${!fb_var}" ]; then
# Check /etc/resolv.conf for nameserver entries
ebegin Verifying DNS configuration
if ! grep -q nameserver /etc/resolv.conf; then
eend 1
# Add fallback name server(s) to /etc/resolv.conf
for nameserver in "${!fb_arr}"; do
ewarn Adding fallback name server $nameserver ...
echo "nameserver $nameserver" >> /etc/resolv.conf
eend $?
done
else
eend 0
einfo DNS is already configured, no fallback required
fi
else
einfo "Nothing to do for '${IFACE}'"
eend 0
fi
# Always return 'success'
return 0
}
|
This is the output for '/etc/init.d/net.eth0 start':
Code: | * Bringing up interface eth0
* dhcp ...
* Running dhcpcd ... [ !! ]
* Trying fallback configuration 10.10.10.10 netmask 255.255.255.0
* 10.10.10.10 ... [ ok ]
* Adding routes
* default via 10.10.10.254 ... [ ok ]
* Running postup ...
* Verifying DNS configuration ... [ !! ]
* Adding fallback name server 10.10.10.254 ... [ ok ]
|
This is the output for '/etc/init.d/net.lo start':
Code: | * Bringing up interface lo
* 127.0.0.1/8 ... [ ok ]
* Adding routes
* 127.0.0.0/8 via 127.0.0.1 ... [ ok ]
* Running postup ...
* Nothing to do for 'lo' [ ok ]
|
|
|
Back to top |
|
|
|