Small script to update the DNS in WireGuard using netconfig
This commit is contained in:
		
					parent
					
						
							
								9227420bf6
							
						
					
				
			
			
				commit
				
					
						e3d662a9fe
					
				
			
		
					 1 changed files with 30 additions and 0 deletions
				
			
		
							
								
								
									
										30
									
								
								update_wg_dns
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										30
									
								
								update_wg_dns
									
										
									
									
									
										Executable file
									
								
							|  | @ -0,0 +1,30 @@ | ||||||
|  | #!/bin/bash | ||||||
|  | 
 | ||||||
|  | NETWORKMANAGER_NETCONFIG="/var/run/netconfig/NetworkManager.netconfig" | ||||||
|  | 
 | ||||||
|  | dns-update() { | ||||||
|  |     tmpfile=$(mktemp) | ||||||
|  |     sed  --regexp-extended "s/(DNSSERVERS=)'(.*?)'/\1'$@ \2'/g" "${NETWORKMANAGER_NETCONFIG}" > "${tmpfile}" | ||||||
|  |     netconfig modify -s NetworkManager -I "${tmpfile}" | ||||||
|  |     rm -f "${tmpfile}" | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | dns-restore() { | ||||||
|  |     tmpfile=$(mktemp) | ||||||
|  |     sed  --regexp-extended "s/$@ //g" "${NETWORKMANAGER_NETCONFIG}" > "${tmpfile}" | ||||||
|  |     netconfig modify -s NetworkManager -I ${tmpfile} | ||||||
|  |     rm -f ${tmpfile} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | dns() { | ||||||
|  |     local cmdname=$1; shift | ||||||
|  |     "dns-$cmdname" "$@" | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | if declare -f "$1" >/dev/null 2>&1; then | ||||||
|  |   # invoke that function, passing arguments through | ||||||
|  |   "$@" # same as "$1" "$2" "$3" ... for full argument list | ||||||
|  | else | ||||||
|  |   echo "Function $1 not recognized" >&2 | ||||||
|  |   exit 1 | ||||||
|  | fi | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue