First off all, please forgive my ignorance.
I am a hobbyist self learned programmer. Patching scripts together and reading manuals is the way I learn to code.
I hope you understand
I have troubles setting a manual DNS. The vpn service I use has a custom vpn which i want to use.
I tried “sudo nano /etc/resolv.conf” but permission was denied. The read out is:
# Generated by Connection Manager
search home
nameserver 208.67.220.220
nameserver 208.67.222.222
nameserver 8.8.8.8
nameserver 8.8.4.4
So i see that also the dns from the ovpn is ignored.
My preferred setup is a rpi running transmission behind a vpn. VPN start immeadlty after boot and kills transmission when the connection is lost. At this moment I have somewhat of a working situation.
and then this script for starting the vpn. I am afraid it might not be fully compatible with osmc. For the reason I am not able to set the DNS (tee command?)
#!/bin/sh
#Script to modify the transmission settings to bind to the VPN IP
#HTPCGuides.com
#enter the /etc/openvpn directory
cd /etc/openvpn
#stop the transmission-daemon
systemctl stop transmission
#Plug the VPN IP into transmission, may need to change $ifconfig_local to $ifconfig_remote
sed -i 's/.*"bind-address-ipv4":.*/ "bind-address-ipv4": \"'$ifconfig_local'\",/' /home/osmc/.config/transmission-daemon/settings.json
#add Open DNS servers, change to Google's 8.8.8.8 and 8.8.4.4 if you like
echo "nameserver 146.148.119.121" | tee -a /etc/resolv.conf
echo "nameserver 104.130.169.74" | tee -a /etc/resolv.conf
# add routing to retain remote access, use either the manual variables or automatic ones not both
MAINIP=192.168.2.190
GATEWAYIP=192.168.2.254
SUBNET=192.168.2.0/24
#automatic IP finding
#MAINIP=$(ip route | awk 'NR==3{print $9}')
#GATEWAYIP=$(ip route | awk 'NR==1{print $3}')
#SUBNET=$(ip route | awk 'NR==2{print $1}')
ip rule add from $MAINIP table 128
ip route add table 128 to $SUBNET dev wlan0
ip route add table 128 default via $GATEWAYIP
#start the transmission.daemon
systemctl restart transmission
Hope anyone can point me in the right direction.
Also setting DHCP to manual in the OSMC GUI didn’t work for setting a manual dns.
Update:
Ok, I am really confused now. Apparently the rc.local script is not running. However, the vpn is initiated at boot. When I do an ip check, the vpn ip is shown. Maybe I have set another run-at-boot method, but I can’t remember what.
Thanks for your input. I applied the script as suggested.
I ran into this problem, it is familiar, I ran into it before I remember now when trying to manually modify resolv.conf.
mv: cannot move '/etc/resolv.conf' to '/etc/resolv.conf.orig': Operation not permitted
/etc/openvpn/updatedns.sh: line 5: /etc/resolv.conf: Permission denied
Fri Feb 3 16:35:41 2017 WARNING: Failed running command (--up/--down): external program exited with error status: 1
Fri Feb 3 16:35:41 2017 Exiting due to fatal error
#!/bin/bash
case "$script_type" in
up)
sudo mv /etc/resolv.conf /etc/resolv.conf.orig
echo "nameserver 146.148.119.121" > sudo /etc/resolv.conf
;;
down)
sudo cp -a /etc/resolv.conf.orig /etc/resolv.conf
;;
esac
and performed: sudo chmod ugo+x /etc/openvpn/updatedns.sh
sudo openvpn --config /etc/openvpn/nl14.ovpn
unfortunately I still get the error
Fri Feb 3 17:15:57 2017 /etc/openvpn/updatedns.sh tun0 1500 1590 10.8.8.238 10.8.8.237 init
sudo: mv: command not found
/etc/openvpn/updatedns.sh: line 5: /etc/resolv.conf: Permission denied
Fri Feb 3 17:15:57 2017 WARNING: Failed running command (--up/--down): external program exited with error status: 1
Fri Feb 3 17:15:57 2017 Exiting due to fatal error
If you guys would properly use the </> preformatted text feature (and not trying to “quote” the text) for you scripts in the post editor, your code would print to this thread in an appropriate and usable fashion. Just a hint…
Yeah I don’t know why i get that when using the updatedns.sh script. update-resolve-conf does not give conflict.
I tried something else. I added these lines for my preferred dns server to the ovpn file:
dhcp-option DNS 146.148.119.121
dhcp-option DNS 104.130.169.74
2.When I initiate the vpn, I get this:
Fri Feb 3 17:33:09 2017 /etc/openvpn/update-resolv-conf tun0 1500 1590 10.8.8.238 10.8.8.237 init
dhcp-option DNS 146.148.119.121
dhcp-option DNS 104.130.169.74
dhcp-option DNS 78.46.223.24
dhcp-option DNS 162.242.211.137
/etc/resolvconf/update.d/libc: Warning: /etc/resolv.conf is not a symbolic link to /etc/resolvconf/run/resolv.conf
3.still this is wat returns when I perform: cat /etc/resolv.conf
# Generated by Connection Manager
search home
nameserver 208.67.220.220
nameserver 208.67.222.222
nameserver 8.8.8.8
nameserver 8.8.4.4
Looking at update-resolve-conf I noticed you have to first CP and then MV at the end of the script. Thus, I managed to get not errors using this script:
#!/bin/bash
case "$script_type" in
up)
cp /etc/resolv.conf /etc/resolv.conf.default
echo "nameserver 146.148.119.121" > sudo /etc/resolv.conf
;;
down)
mv -a /etc/resolv.conf.default /etc/resolv.conf
;;
esac
If I use sudo in front instead. I get the permission error for /etc/resolv.conf again:
If ConnMan will overwrite everything again in the same session, then this might not be a sustainable solution in the end. I would like to read up how to configure OpenVPN via Connman.