Last active
September 20, 2018 09:46
-
-
Save allenyllee/c11c150842578d514c6a46caaaa7e1ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Command-line to list DNS servers used by my system - Ask Ubuntu | |
# https://askubuntu.com/questions/152593/command-line-to-list-dns-servers-used-by-my-system | |
DEVICE_NAME="eno1" | |
# get interface name | |
interface=$(nmcli device | grep "$DEVICE_NAME" | cut -d' ' -f1) | |
# list dns | |
echo DNS of $interface | |
nmcli -t -f IP4.DNS device show "$interface" | cut -d':' -f2 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# networking - How to manage DNS in NetworkManager via console (nmcli)? - Server Fault | |
# https://serverfault.com/questions/810636/how-to-manage-dns-in-networkmanager-via-console-nmcli | |
# | |
# | |
DNS_IP="1.1.1.1, 1.0.0.1, 8.8.8.8, 8.8.4.4" | |
DEVICE_NAME="eno1" | |
# get interface name | |
interface=$(nmcli -t device | grep "$DEVICE_NAME" | cut -d: -f1) | |
# get connection name | |
connection=$(nmcli -t connection show --active | grep "$DEVICE_NAME" | cut -d: -f1) | |
echo "interface: $interface" | |
echo "connection: $connection" | |
# disable auto-dns | |
nmcli con mod "$connection" ipv4.ignore-auto-dns yes | |
# show result | |
nmcli -t -f ipv4.ignore-auto-dns con show "$connection" | |
# set dns at connection | |
nmcli con mod "$connection" ipv4.dns "$DNS_IP" | |
# show result | |
nmcli -t -f ipv4.dns con show "$connection" | |
# set dns at interface (take effect immediately) | |
nmcli dev mod "$interface" ipv4.dns "$DNS_IP" | |
# show result | |
nmcli -t -f IP4.DNS dev show "$interface" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# command line - stay connected to wifi when all users log out - Ask Ubuntu | |
# https://askubuntu.com/questions/1064959/stay-connected-to-wifi-when-all-users-log-out | |
DEVICE_NAME="wlo1" | |
# get interface name | |
interface=$(nmcli -t device | grep "$DEVICE_NAME" | cut -d: -f1) | |
# get connection name | |
connection=$(nmcli -t connection show --active | grep "$DEVICE_NAME" | cut -d: -f1) | |
echo "interface: $interface" | |
echo "connection: $connection" | |
# set permissions (for all users) | |
nmcli connection modify "$connection" connection.permissions '' | |
# show result | |
nmcli -t -f connection.permissions con show "$connection" | |
# set autoconnect | |
nmcli connection modify "$connection" connection.autoconnect yes | |
# show result | |
nmcli -t -f connection.autoconnect con show "$connection" | |
# set autoconnect-priority | |
nmcli connection modify "$connection" connection.autoconnect-priority 10 | |
# show result | |
nmcli -t -f connection.autoconnect-priority con show "$connection" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment