How to get an usable DNS

This forum is for discussion about general software issues.

How to get an usable DNS

Postby TheSaint » Wed Oct 24, 2018 9:33 pm

Hello forum,

I'm trying to solve the issue that my SBC cannot find any DNS server.
I set netctl to start WPA connection, which calls resolvconf to determine the DNS to use, pretty fine. But there's also systemd-resolved that will try to do the same business. So actually I can't have any DNS available.
If I do SSH over the wire, then also the route is messed up and try to bring the access over the ethernet.
I disable systemd-resolved, but the /etc/resolv.conf still a symlink to somewhere and is not writable. I'd like to get rid of these contentions and put the most commonly used name server into /etc/resolv.conf, but I'm not able to solve it yet.
Furthermore I'm planning to use dnsmasq and hostapd because I would get the SBC set as router.
Anyway, just one of the three program should do that business, or none.
Any input ?
TheSaint
 
Posts: 346
Joined: Mon Jul 23, 2018 7:57 am

Re: How to get an usable DNS

Postby summers » Thu Oct 25, 2018 2:36 pm

DNS is usually set via dhcp, e.g. when you call 'dhcpcd'

Usually the DNS server is saved in /etc/resolv.conf, but under systemd that is a link into /run/systemd/resolve/resolv.conf.

If you are desperate, then remove the link, and put 8.8.8.8 in /etc/resolv.conf - that is google dns
summers
 
Posts: 984
Joined: Sat Sep 06, 2014 12:56 pm

Re: How to get an usable DNS

Postby TheSaint » Thu Oct 25, 2018 3:20 pm

$this->bbcode_second_pass_quote('summers', 'D')NS is usually set via dhcp, e.g. when you call 'dhcpcd'

I'm planning to use dnsmasq as server, therefore no dhcpcd.
$this->bbcode_second_pass_quote('summers', 't')hen remove the link, and put 8.8.8.8 in /etc/resolv.conf - that is google dns

I did it, but I prefer the opendns.org . I need to know how to stop these conflicts and let DHCP server do the job.
TheSaint
 
Posts: 346
Joined: Mon Jul 23, 2018 7:57 am

Re: How to get an usable DNS

Postby summers » Fri Oct 26, 2018 10:25 am

'dnsmasq' is what is run on the dns/dhcp server, e.g. its what I run on my openwrt router ...

'dhcpcd' is what runs on the client, that asks for ip details.

Check the standard systemd set up in a bit more detail: https://wiki.archlinux.org/index.php?title=Systemd-resolved&redirect=no.

You can get the current status by using $this->bbcode_second_pass_code('', 'resolvectl status')

The arch link gives how to set up default dns servers for if dhcp fails.
summers
 
Posts: 984
Joined: Sat Sep 06, 2014 12:56 pm

Re: How to get an usable DNS

Postby TheSaint » Sat Oct 27, 2018 1:04 am

I disabled systemd-resolved even thought is requested by netctl. So I should plan a simple call to wpa_supplicant if I want to connect to an AP, then I may try dnsmasq to resolve the DNS matters.

Anyway, as you pointed out, the systemd-resolved uses the /etc/resolv.conf whether the other programs may change it.

In my needs, I want to set an AP, so dnsmasq would work as DHCP server and as DNS server when can connect to the internet. The problem arise when I connect the cable and the resolver put the default route to the cable, which is going nowhere. The route should remain to the wireless connection and the DNS should remain asserted to dnsmasq.

I think I have to study what should manage the connections and routes. Perhaps it should be systemd-networkd, but I feel that systemd is becoming too intrusive, for my tastes.
TheSaint
 
Posts: 346
Joined: Mon Jul 23, 2018 7:57 am

Re: How to get an usable DNS

Postby summers » Sun Oct 28, 2018 8:29 am

OK lets go over the various bits. My Openwrt router runs dnsmasq. Its configuration file is:
$this->bbcode_second_pass_code('', '# auto-generated config file from /etc/config/dhcp
conf-file=/etc/dnsmasq.conf
dhcp-authoritative
domain-needed
localise-queries
read-ethers
expand-hosts
local-service
domain=lan
server=/lan/
dhcp-leasefile=/tmp/dhcp.leases
resolv-file=/tmp/resolv.conf.auto
stop-dns-rebind
rebind-localhost-ok
dhcp-broadcast=tag:needs-broadcast
addn-hosts=/tmp/hosts
conf-dir=/tmp/dnsmasq.d
user=dnsmasq
group=dnsmasq




bogus-priv
conf-file=/usr/share/dnsmasq/rfc6761.conf
dhcp-range=set:lan,192.168.2.100,192.168.2.249,255.255.255.0,12h



')
The file resolv.conf.auto is
$this->bbcode_second_pass_code('', '# Interface wan
nameserver 212.159.6.9
nameserver 212.159.6.10
')
Those are the dns servies give out when the adsl connections comes up via dhcp. Now dnsmasq doesn't export those. It gives the number of the router as the dns server - so it DNS queries go through to the router, and that forwards onto the WAN.

Now down in the LAN on my local machine. The local systemd file : /etc/systemd/network/wlp3s0.network
$this->bbcode_second_pass_code('', '[Match]
Name=wlp3s0

[Network]
DHCP=ipv4
IPv6PrivacyExtensions=yes

[DHCP]
RouteMetric=20
')
wlp3s0 is the cryptic name for my wifi connection, so wifi is brought up and connects to the router via dhcp.

That gives the ip number, and also the dns details. I am running systemd-resolved - and actually reading its documentation - it does do a reasonable job. Anyway when dhcp is brought up on wifi, that does pass on the dns details onto systemd-resolved and for me that sents the dns in /etc/resolv.conf to 192.168.2.1 - the address of the router ...

So for me it works fine ...
summers
 
Posts: 984
Joined: Sat Sep 06, 2014 12:56 pm

Re: How to get an usable DNS

Postby TheSaint » Mon Oct 29, 2018 1:03 am

Always thank you for your great inputs.
I think I'll give a try, but I didn't understand how the network is brought up. Are you using systemd-networkd.socket ?

I would set the TB as AP, then if a second WiFi dongle is plugged in, it will get the connection to internet (if any) and share the connection.
So for that I'm trying to write a script that it will be called by udev and a periodic check should try to get a hotspot to connect to.
In case there's no internet available, it should fall back to a normal AP.
My script$this->bbcode_second_pass_code('', '#!/bin/bash
# Usage: ./initSoftAP

remove() {
if [ -z "$(ps -e | grep $1)" ]
then
killall $1
fi
}
setdev () {
########### Initial wifi interface configuration #############
ip link set $1 down
ip addr flush dev $1
ip link set $1 up
}

setDWA() {
# check for second interface connection
foundWLAN1=$(lsusb | grep -c DWA)
if [ $foundWLAN1 -eq 1 ]; then
setdev $1 > /dev/null 2>&1 &&
wpa_supplicant -B -i $1 -c /etc/wpa_supplicant/wpa_supplicant.conf\
> /dev/null 2>&1 &&
dhcpcd $1 > /dev/null 2>&1 &&
return 1
else
if [ -e /run/wpa_supplicant/$1 ]; then
rm -f /run/wpa_supplicant/$1
fi
remove wpa_supplicant
remove dhcpcd
return 0
fi
}

stopserv() {
remove wpa_supplicant
remove dhcpcd
remove dnsmasq
ip link set dev $1 down
}

startap() {
###################### Enable NAT ############
iptables -t nat -A POSTROUTING -o $2 -j MASQUERADE
iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i $1 -o $2 -j ACCEPT
sysctl -w net.ipv4.ip_forward=1
##################### Start hostapd ###########
hostapd /tmp/hostapd-test.conf
dnsmasq
}

# setdev $1
# ip addr add 10.0.0.1/24 dev $1
# remove dnsmasq
# sleep 2
#
# if setDWA $2 ; then
# startap $1 $2
# else
# hostapd /tmp/hostapd-test.conf
# fi
')
Actually it's meant to be call by a systemd service.
I think I will manage to get the first function to get the return value, which I don't understand yet. But the script might be a bit different if it will be called by udev. Udev should give an action when plugging in and another when removed, so the program is kept running just when the second device is present. As you may figure out that the on board chip doesn't support AP and managed traffic.
TheSaint
 
Posts: 346
Joined: Mon Jul 23, 2018 7:57 am

Re: How to get an usable DNS

Postby summers » Mon Oct 29, 2018 8:07 pm

$this->bbcode_second_pass_code('', '$ systemctl status systemd-resolved
● systemd-resolved.service - Network Name Resolution
Loaded: loaded (/usr/lib/systemd/system/systemd-resolved.service; enabled; v>
Active: active (running) since Fri 2018-10-12 08:39:54 BST; 2 weeks 3 days a>
Docs: man:systemd-resolved.service(8)
https://www.freedesktop.org/wiki/Software/systemd/resolved
https://www.freedesktop.org/wiki/Software/systemd/writing-network-co>
https://www.freedesktop.org/wiki/Software/systemd/writing-resolver-c>
Main PID: 345 (systemd-resolve)
Status: "Processing requests..."
Tasks: 1 (limit: 4915)
Memory: 10.0M
CGroup: /system.slice/systemd-resolved.service
└─345 /usr/lib/systemd/systemd-resolved

Warning: Journal has been rotated since unit was started. Log output is incompl>
$ systemctl status systemd-networkd
● systemd-networkd.service - Network Service
Loaded: loaded (/usr/lib/systemd/system/systemd-networkd.service; enabled; v>
Active: active (running) since Fri 2018-10-12 08:39:53 BST; 2 weeks 3 days a>
Docs: man:systemd-networkd.service(8)
Main PID: 342 (systemd-network)
Status: "Processing requests..."
Tasks: 1 (limit: 4915)
Memory: 2.2M
CGroup: /system.slice/systemd-networkd.service
└─342 /usr/lib/systemd/systemd-networkd

Warning: Journal has been rotated since unit was started. Log output is incomp')

So running both networkd and reolved.

When I started using arch, and first encountered systemd - I used several of the add on packages as that was what I was used to. But over time I've switched 100% to anything that systemd can do native, then let it do that. Basically becuase the default set up is very good, and you can make changes if needed. Hassle is using a new bit of software, and discovering quite how much systemd does, and does in parallel ...
summers
 
Posts: 984
Joined: Sat Sep 06, 2014 12:56 pm

Re: How to get an usable DNS

Postby TheSaint » Tue Oct 30, 2018 2:56 am

Sorry, you wrote it and I oversight that you're using systemd :)
As you explained, I got the point that if I'll set systemd then the internet connection would be handled by systemd. So I may give a preference on that, but the dnsmasq should be arranged accordingly, I think.
I'm a bit confused, the case when the internet is not available, dnsmasq will work just as DHCP server, but when the internet is available should give the DNS service to the clients. Shouldn't it be necessary to restart dnsmasq?

BTW the first configuration that you shown is not part of Arch, that is OpenWRT stuff. Therefore I need to write dnsmasq manually.
TheSaint
 
Posts: 346
Joined: Mon Jul 23, 2018 7:57 am

Re: How to get an usable DNS

Postby summers » Tue Oct 30, 2018 6:13 am

Yes dnsmasq runs for me on openwrt. I think it comes up at boot, which is before the ADSL connection has come up. I think it already is giving out DNS numbers at that stage - but it only gives the number of the machine its on. Suspect that its own connection to DNS only happens when the ADSL comes up and ppp then supplies WAN DNS numbers ...
summers
 
Posts: 984
Joined: Sat Sep 06, 2014 12:56 pm

Next

Return to General

Who is online

Users browsing this forum: No registered users and 15 guests