rk3288 ubuntu 网卡管理
sudo echo "nameserver 223.5.5.5" > /etc/resolv.conf
NetworkManager设置
nmcli:命令行。这是最常用的工具。
nmtui:在shell终端开启文本图形界面。
Freedesktop applet:如GNOME上自带的网络管理工具
nm-connection-editor图形配置工具
cockpit:redhat自带的基于web图形界面的"驾驶舱"工具,具有dashborad和基础管理功能。
1.禁用NetworkManager使用 dnsmasq-base 关掉Ubuntu内置的dnsmasq服务
这样就不会使用127.0.0.1:53 了,每个网络连接就可以使用自己定义的dnsvi /etc/NetworkManager/NetworkManager.conf
[main]
plugins=ifupdown,keyfile,ofono
#dns=dnsmasq
[ifupdown]
managed=false
- Ubuntu 18.04设置dns
最近使用了最新版的ubuntu 18.04运行一些服务,然后发现服务器经常出现网络不通的情况,主要是一些域名无法解析。
检查/etc/resolv.conf,发现之前修改的nameserver总是会被修改为127.0.0.53,无论是改成啥,过段时间,总会变回来。
查看/etc/resolv.conf这个文件的注释,发现开头就写着这么一行:
This file is managed by man:systemd-resolved(8). Do not edit.
这说明这个文件是被systemd-resolved这个服务托管的。
通过netstat -tnpl| grep systemd-resolved
查看到这个服务是监听在53号端口上。
查了下,这个服务的配置文件为/etc/systemd/resolved.conf
,大致内容如下:
[Resolve]
DNS=1.1.1.1 1.0.0.1
#FallbackDNS=
#Domains=
LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#Cache=yes
#DNSStubListener=yes
如果我们要想让/etc/resolve.conf文件里的配置生效,需要添加到systemd-resolved的这个配置文件里DNS配置项(如上面的示例,已经完成修改),然后重启systemd-resolved服务即可。
另一种更简单的办法是,我们直接停掉systemd-resolved服务,这样再修改/etc/resolve.conf就可以一直生效了。
ubuntu 16.04 解决DNS重启被重置的问题
vi /etc/systemd/resolv.conf
vim /etc/systemd/resolved.conf
[Resolve]
DNS=119.29.29.29 223.5.5.5 #多个DNS地址使用空格分隔
#FallbackDNS=
#Domains=
#LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#DNSOverTLS=no
#Cache=yes
#DNSStubListener=yes
resolvectl status
查看
nmcli dev wifi connect TP-LINK_5G_649D password xinliankong666
nmcli conn add type ethernet con-name "eth0-static" ifname eth0 autoconnect yes ip4 192.168.0.10/24 gw4 192.168.0.2
连接wifi:nmcli dev wifi connect wifiname password wifipassword
关闭wifi:nmcli dev disconnect wlan0
nmcli命令生效:nmclicon down wlan0 ; nmclicon up wlan0
2)配置文件:/etc/NetworkManager/NetworkManager.conf
修改配置文件执行生效:systemctl restart network 或 nmcli con reload
3)wifi相关
扫描wifi: nmcli device wifi
#### 关闭/打开 所有无线网卡:
nmcli r wifi off
nmcli r wifi on
查看所有连接: nmcli con show
如果未找到dhclient进行,则确认dhclient进程未运行,执行以下命令,继续排查NetworkManager是否运行。
systemctl status NetworkManager
场景一:如果NetworkManager的状态为Active: inactive (dead)(如果状态为running进入•场景二:如果NetworkManager的状态...),则NetworkManager未启动,执行以下命令,检查该服务是否开机自启。
systemctl is-enabled NetworkManager
结果为disabled则确认为NetworkManager为设置开机自启导致,执行以下命令进行恢复。
systemctl enable NetworkManager && systemctl start NetworkManager
场景二:如果NetworkManager的状态为Active: active (running),执行以下命令查看网卡设备是否被NetworkManager管理。
nmcli device status
如果显示该网卡为的STATE为unmanaged,则该网卡设备未被NetworkManager管理,执行以下命令进行恢复。
nmcli device set eth0 managed yes
(Network Manager网络配置)[http://wiki.t-firefly.com/zh_CN/AIO-3288J/linux_ubuntu_server.html]
(Network Manager工具 nmcli)[https://www.cnblogs.com/1477717815fuming/p/7499108.html]
Ubuntu Server 使用
网络
默认使用 Network Manager 来管理以太网和 WiFi。
以太网 eth0设备管理
断开以太网(重启后不再自动连接):nmcli dev disconnect iface eth0
打开以太网连接:nmcli con up id "Ethernet connection 1"
关闭以太网连接:nmcli con down id "Ethernet connection 1"
nmcli 配置静态 IP
查看一个连接nmcli conn
删除一个连接nmcli c del 'Wired connection 1'
创建一个连接(connection) con-name 不要使用 "eth0" 启动时会被删除nmcli conn add type ethernet con-name "eth0-dhcp" ifname eth0
nmcli conn add type ethernet con-name "eth0-static" ifname eth0 autoconnect yes ip4 192.168.0.10/24 gw4 192.168.0.1
nmcli conn mod eth0-static ipv4.gateway "192.168.0.2"
修改一个连接
nmcli conn mod eth0-static ipv4.method manual //配置IP地址获取方式为手动
nmcli conn mod eth0-static ipv4.addresses "192.168.0.10/24" //配置IP和掩码
nmcli conn mod eth0-static ipv4.gateway "192.168.0.2" //配置网关
nmcli conn mod eth0-static ipv4.route-metric 500 //配置路由表优先级
nmcli conn mod eth0-static connection.autoconnect yes // 配置开机自动启动
nmcli conn mod eth0-static -ipv4.dns 8.8.8.8 //删除 DNS
nmcli conn mod eth0-static ipv4.dns "223.5.5.5"
nmcli conn up eth0-static //启动网卡
nmcli con mod eth0-static ipv4.method manual ipv4.addr "192.168.1.2/24, 10.10.1.5/8" ipv4.route-metric 500
//设置多个ip地址
以太网的连接配置文件为:
"/etc/NetworkManager/system-connections/Ethernet connection 1"
其内容为:
[connection]
id=Ethernet connection 1
uuid=d4050376-8790-4b83-ae24-015412398a61
interface-name=eth0
type=ethernet
[ipv6]
method=auto
[ipv4]
method=auto
默认使用 DHCP 来获取动态 IP 地址。 要指定静态 IP 地址,需要更改 "ipv4"
一节成:
[ipv4]
method=manual
address1=192.168.0.100/24,192.168.0.1
dns=8.8.8.8;8.8.4.4;
address1 行的格式为:
address1= 列出可用的 WiFi 存取点: 创建名称为“My cafe"的新连接,使用密码 "caffeine" 连接到 "Cafe Hotspot 列出可用的网络连接: 关闭 "My cafe" 网络连接: 打开 "My cafe" 网络连接: 显示 WiFi 打开状态: 打开 WiFi: 关闭 WiFi: 第一步:创建软件网桥接口并配上地址 第二步:创建网桥的从属接口 nmcli con add type bridge-slave ifname ens33 master br0 nmcli con add type bridge-slave ifname ens34 master br0 第三步:启动网桥接口和从属接口 nmcli con up br0 nmcli con up bridge-slave-ens33 nmcli con up bridge-slave-ens34 https://github.com/spieglt/FlyingCarpet/blob/master/core/network_linux.go 点击保存后,可以在/etc/NetworkManager/system-connections/下看到刚创建的连接对应的wifi-test文件: 打开该文件: 可以发现已经使用了mode=ap模式,使用了wpa-psk来认证,psk显示了认证的密码,同时ipv4的method=shared,ipv6的method=ignore,说明界面的操作最后都保留到这个文件中。如果无线网卡真的支持AP,则就算前面的界面中没有热点这个选项,也可以修改这个配置文件的mode=ap来实现,因为Linux中一切皆为文件。 ##删除 Network Manager 管理的 dnsmasq ps aux|grep dns cat /etc/NetworkManager/dnsmasq.d/cache 4、显示指定网络连接的详情:nmcli con show eno16777728 5、显示指定网络设备的详情:nmcli dev show eno16777728配置无线WiFi
nmcli dev wifi
1" SSID:nmcli dev wifi connect "Cafe Hotspot 1" password "caffeine" name "My cafe"
nmcli con list
nmcli con down id "My cafe"
nmcli con up id "My cafe"
nmcli nm wifi
nmcli nm wifi on
nmcli nm wifi off
连接无线网络
nmcli dev wifi connect HUAWEI-B315-3446 password 23224913
nmcli dev wifi connect HUAWEI-B315-CE02 password 08908429
nmcli dev wifi connect HUAWEI-B315-D4C4 password 00252225
nmcli dev wifi connect HUAWEI-B315-0089 password 08194820
17305393014配置实现网桥 wlan0 eth0
nmcli con add type bridge con-name br0 ifname br0 ipv4.method manual ipv4.addresses 192.168.0.100
开启wifi ap模式 ****
apPath=/etc/NetworkManager/system-connections/wifiAP
if [ ! -d "$apPath"]; then
nmcli con up wifiAP
fi
#rm $apPath
#nmcli con add con-name APHost type wifi ifname wlan0 ssid SmartHomeAP mode ap -- ipv4.method shared
#nmcli con up APHost
#不存在
`nmcli con add con-name wifi type wifi ifname wlan0 ssid SmartHomeAP mode ap -- ipv4.method shared ipv4.addresses 192.168.42.1/24`
nmcli con up wifi
# setup hotspot
nmcli con add type wifi ifname wlan0 con-name Hostspot autoconnect yes ssid Hostspot
nmcli con modify Hostspot 802-11-wireless.mode ap 802-11-wireless.band bg ipv4.method shared
nmcli con modify Hostspot wifi-sec.key-mgmt wpa-psk
nmcli con modify Hostspot wifi-sec.psk "veryveryhardpassword1234"
nmcli con up Hostspot
# simple connection
nmcli dev wifi connect NewNetwork password veryveryhardpassword1234
#!/bin/bash
SSID="NeutisN5"
PASSWORD="12345678"
nmcli con add \
type wifi \
ifname wlan0 \
con-name $SSID \
autoconnect no \
ssid $SSID
nmcli con modify $SSID \
802-11-wireless.mode ap \
802-11-wireless.band bg \
wifi-sec.proto rsn \
wifi-sec.pairwise ccmp \
wifi-sec.group ccmp \
wifi-sec.key-mgmt wpa-psk \
wifi-sec.psk $PASSWORD \
ipv4.method shared \
ipv4.addresses 192.168.42.1/24 \
ipv6.method ignore
nmcli con up $SSID
[connection]
id=wifi-test
uuid=ebd62f6f-b5b5-46d7-becf-bd3f17efa753
type=wifi
permissions=
secondaries=
[wifi]
mac-address-blacklist=
mac-address-randomization=0
mode=ap
seen-bssids=
ssid=wifi-test
[wifi-security]
group=
key-mgmt=wpa-psk
pairwise=
proto=
psk=你的wifi密码
[ipv4]
dns-search=
method=shared
[ipv6]
addr-gen-mode=stable-privacy
dns-search=
ip6-privacy=0
method=ignore
- name: Check if NetworkManager and Dnsmasq are installed
yum: name={{ item }} state=present
with_items:
- NetworkManager
- NetworkManager-wifi
- dnsmasq
- chrony
tags:
- nmcli
- dnsmasq
- name: Start the chrony service
service: name=chronyd state=started enabled=yes
tags: packages
- name: Check if wifi device exists and exit if not
shell: /usr/bin/nmcli device status | grep wifi
register: nmcli_result
ignore_errors: False
tags: nmcli
- name: Assign wifi device name to variable
shell: /usr/bin/nmcli device status | grep wifi | cut -d' ' -f1
register: wlan_ap_device
tags: nmcli
- name: Run nmcli to check if wifi access point connection has already been added
shell: /usr/bin/nmcli c | grep {{ wlan_ap_ssid }}
register: nmcli_result
ignore_errors: True
tags: nmcli
- name: Run nmcli to add a connection with the specified parameters as a wifi access point if above check has failed
command: /usr/bin/nmcli c add autoconnect yes save yes con-name {{ wlan_ap_ssid }} ifname {{ wlan_ap_device.stdout }} type wifi ssid {{ wlan_ap_ssid }} mode ap ip4 {{ wlan_ap_ipaddress }}
when: nmcli_result | failed
tags: nmcli
- name: Run nmcli to add WPA-PSK security to the wifi connection
command: /usr/bin/nmcli c mod {{ wlan_ap_ssid }} 802-11-wireless-security.key-mgmt wpa-psk 802-11-wireless-security.psk {{ wlan_ap_secret }} 802-11-wireless-security.pairwise ccmp, 802-11-wireless-security.proto rsn
tags: nmcli
- name: Run nmcli to activate wifi access point connection
command: /usr/bin/nmcli c up {{ wlan_ap_ssid }}
tags: nmcli
- name: Add nmcli c up {{ wlan_ap_ssid }} to /etc/rc.local to workaround a bug in systemd
shell: grep "nmcli c up {{ wlan_ap_ssid }}" /etc/rc.local || echo "/usr/bin/nmcli c up {{ wlan_ap_ssid }}" >> /etc/rc.local
tags: nmcli
- name: Make /etc/rc.d/rc.local executable to enable the previous fix
file: path=/etc/rc.d/rc.local mode="u+x"
tags: nmcli
# maybe add source={{ wlan_ap_ipaddress }} if ansible version >=2.0
- name: Insert firewalld rule for DNS port 52
firewalld: service=dns permanent=true state=enabled immediate=yes
tags: dnsmasq
- name: Insert firewalld rule for DHCP port 67
firewalld: service=dhcp permanent=true state=enabled immediate=yes
tags: dnsmasq
- name: Run firewall-cmd to add masquerading permanently
command: /usr/bin/firewall-cmd --permanent --add-masquerade
tags: dnsmasq
- name: Run firewall-cmd to add masquerading immediately (just to be sure it's actived in case the expected reboot is not happening)
command: /usr/bin/firewall-cmd --add-masquerade
tags: dnsmasq
- name: Configure Dnsmasq
template: src=dnsmasq-wlan_ap.j2 dest=/etc/dnsmasq.d/dnsmasq-wlan_ap.conf
tags: dnsmasq
- name: Enable and start Dnsmaq
service: name=dnsmasq state=started enabled=yes
tags: dnsmasq
sed -i 's/^dns=dnsmasq/# dns=dnsmasq/g' /etc/NetworkManager/NetworkManager.conf
service network-manager restart
管理DNS
nobody 581 0.0 0.1 7548 2992 ? S 05:54 0:00 /usr/sbin/dnsmasq --no-resolv --keep-in-foreground --no-hosts --bind-interfaces --pid-file=/var/run/NetworkManager/dnsmasq.pid --listen-address=127.0.1.1 --cache-size=0 --conf-file=/dev/null --proxy-dnssec --enable-dbus=org.freedesktop.NetworkManager.dnsmasq --conf-dir=/etc/NetworkManager/dnsmasq.d
cache-size=1000查看nmcli 具体参数
nmcli con show eth0-static
[root@centos7 ~]# nmcli con show eno16777728
connection.id: eno16777728
connection.uuid: 8cedbaed-b1ed-aa77-7f3c-6b5a960f4bb5
connection.interface-name: eno16777728
connection.type: 802-3-ethernet
connection.autoconnect: yes
connection.autoconnect-priority: 0
connection.timestamp: 1473150860
connection.read-only: no
connection.permissions:
connection.zone: --
connection.master: --
connection.slave-type: --
connection.autoconnect-slaves: -1 (default)
connection.secondaries:
connection.gateway-ping-timeout: 0
connection.metered: unknown
802-3-ethernet.port: --
802-3-ethernet.speed: 0
802-3-ethernet.duplex: --
802-3-ethernet.auto-negotiate: yes
802-3-ethernet.mac-address: --
802-3-ethernet.cloned-mac-address: --
802-3-ethernet.mac-address-blacklist:
802-3-ethernet.mtu: auto
802-3-ethernet.s390-subchannels:
802-3-ethernet.s390-nettype: --
802-3-ethernet.s390-options:
802-3-ethernet.wake-on-lan: 1 (default)
802-3-ethernet.wake-on-lan-password: --
ipv4.method: manual
ipv4.dns:
ipv4.dns-search:
ipv4.addresses: 10.1.254.254/16
ipv4.gateway: --
ipv4.routes:
ipv4.route-metric: -1
ipv4.ignore-auto-routes: no
ipv4.ignore-auto-dns: no
ipv4.dhcp-client-id: --
ipv4.dhcp-send-hostname: yes
ipv4.dhcp-hostname: --
ipv4.never-default: no
ipv4.may-fail: yes
ipv6.method: ignore
ipv6.dns:
ipv6.dns-search:
ipv6.addresses:
ipv6.gateway: --
ipv6.routes:
ipv6.route-metric: -1
ipv6.ignore-auto-routes: no
ipv6.ignore-auto-dns: no
ipv6.never-default: no
ipv6.may-fail: yes
ipv6.ip6-privacy: -1 (unknown)
ipv6.dhcp-send-hostname: yes
ipv6.dhcp-hostname: --
GENERAL.NAME: System eno16777728
GENERAL.UUID: 8cedbaed-b1ed-aa77-7f3c-6b5a960f4bb5
GENERAL.DEVICES: eno16777728
GENERAL.STATE: activated
GENERAL.DEFAULT: no
GENERAL.DEFAULT6: no
GENERAL.VPN: no
GENERAL.ZONE: --
GENERAL.DBUS-PATH: /org/freedesktop/NetworkManager/ActiveConnection/4
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/Settings/3
GENERAL.SPEC-OBJECT: /
GENERAL.MASTER-PATH: --
IP4.ADDRESS[1]: 10.1.254.254/16
IP4.GATEWAY:
IP6.ADDRESS[1]: fe80::20c:29ff:fe06:f987/64
IP6.GATEWAY:
[root@centos7 ~]#
[root@centos7 ~]# nmcli dev show eno16777728
GENERAL.DEVICE: eno16777728
GENERAL.TYPE: ethernet
GENERAL.HWADDR: 00:0C:29:06:F9:87
GENERAL.MTU: 1500
GENERAL.STATE: 100 (connected)
GENERAL.CONNECTION: System eno16777728
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/4
WIRED-PROPERTIES.CARRIER: on
IP4.ADDRESS[1]: 10.1.254.254/16
IP4.GATEWAY:
IP6.ADDRESS[1]: fe80::20c:29ff:fe06:f987/64
IP6.GATEWAY: