设置静态ip
vim /etc/network/interfaces
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# interfaces(5) file used by ifup(8) and ifdown(8) auto lo iface lo inet loopback # The primary network interface auto ens33 #iface eth0 inet dhcp iface ens33 inet static address 192.168.66.222 netmask 255.255.255.0 gateway 192.168.66.254 |
注意上面的网卡名称 要换成你自己机器的名称
设置DNS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# vim /etc/resolv.conf 添加如下内容(这点所有Linux发行版都通用): nameserver 192.168.66.254 nameserver 8.8.8.8 保存退出。 注意:重启Ubuntu后发现又不能上网了,问题出在/etc/resolv.conf。重启后,此文件配置的dns又被自动修改为默认值。所以需要永久性修改DNS。方法如下: # vim /etc/resolvconf/resolv.conf.d/base nameserver 192.168.66.254 nameserver 8.8.8.8 要想修改resolv.conf重启后不被修改,那么进行如下操作。 1.关闭systemd-resolvd服务 systemctl stop systemd-resolvd systemctl disable systemd-resolvd 这样对/etc/resolv.conf做出的修改都能保存下来。 2.unbound自动配置 sudo systemctl stop systemd-resolved sudo systemctl disable systemd-resolved sudo apt install unbound sudo rm -rf /etc/resolv.conf sudo vim /etc/NetworkManager/NetworkManager.conf 重启电脑即可,开机查看resolve.conf发现nameserver自动配置 参考链接:https://blog.csdn.net/midae/article/details/92403306 |
3、重启networking服务使其生效
1 |
# /etc/init.d/networking restart |
关闭图形界面,使用图形界面登录
1 2 3 4 |
。sudo systemctl set-default multi-user.target sudo reboot 开启用户图形界面。sudo systemctl set-default graphical.target sudo reboot |
关闭防火墙
1 2 3 |
ufw status |
设置允许ssh连接
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
启ssh服务首先需要安装打开ssh服务的库: sudo apt-get install openssh-server 检查当前的ssh开启情况: ps -e |grep ssh 如果有sshd,则ssh-server已经启动;若仅有agent,则尚未启动; 开启ssh服务: /etc/init.d/ssh start 若为启动或者希望重启ssh,则修改配置并重启ssh服务: vi /etc/ssh/sshd_config 则可以看到配置文件,按照需求修改即可; 重启ssh: sudo /etc/init.d/ssh restart ubuntu 设置允许ssh远程连接 1. 支持ssh root连接,在文献中提到的 sudo vim /etc/ssh/sshd_config 底部插入 PermitRootLogin yes ssh重启 sudo service ssh restart |
ubuntu 18.4 使用 Netplan 配置网络教程
1、查看配置文件
1 |
ls /etc/netplan/ |
2、打开配置文件
1 |
vim /etc/netplan/*.yaml |
3、修改配置文件
3.1 使用 DHCP分配ip:
1 2 3 4 5 6 |
network: version: 2 renderer: networkd ethernets: enp3s0: dhcp4: true |
3.2 配置静态ip
1 2 3 4 5 6 7 8 9 10 |
network: version: 2 renderer: networkd ethernets: eno1: addresses: - 192.168.188.239/24 gateway4: 255.255.255.0 nameservers: addresses: [192.168.188.1,114.114.114.114] |
or
1 2 3 4 5 6 7 8 9 |
network: version: 2 renderer: networkd ethernets: eno1: addresses: [192.168.188.239/24] gateway4: 255.255.255.0 nameservers: addresses: [192.168.188.1,114.114.114.114] |
3.3 多个网口 DHCP:
1 2 3 4 5 6 7 8 9 10 11 |
network: version: 2 ethernets: enred: dhcp4: yes dhcp4-overrides: route-metric: 100 engreen: dhcp4: yes dhcp4-overrides: route-metric: 200 |
3.4连接开放的 WiFi(无密码):
1 2 3 4 5 6 7 |
network: version: 2 wifis: wl0: access-points: opennetwork: {} dhcp4: yes |
3.5 连接 WPA 加密的 WiFi:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
network: version: 2 renderer: networkd wifis: wlp2s0b1: dhcp4: no dhcp6: no addresses: [192.168.0.21/24] gateway4: 192.168.0.1 nameservers: addresses: [192.168.0.1, 8.8.8.8] access-points: "network_ssid_name": password: "**********" |
3.6 在单网卡上使用多个 IP 地址(同一网段):
1 2 3 4 5 6 7 8 9 |
network: version: 2 renderer: networkd ethernets: enp3s0: addresses: - 10.100.1.38/24 - 10.100.1.39/24 gateway4: 10.100.1.1 |
3.7 在单网卡使用多个不同网段的 IP 地址:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
network: version: 2 renderer: networkd ethernets: enp3s0: addresses: - 9.0.0.9/24 - 10.0.0.10/24 - 11.0.0.11/24 #gateway4: # unset, since we configure routes below routes: - to: 0.0.0.0/0 via: 9.0.0.1 metric: 100 - to: 0.0.0.0/0 via: 10.0.0.1 metric: 100 - to: 0.0.0.0/0 via: 11.0.0.1 metric: 100 |
4、测试配置文件
1 |
sudo netplan try |
如果没问题,可以继续往下应用。
5、应用配置文件
1 |
sudo netplan apply |
6、重启网络服务
1 2 3 4 5 |
sudo systemctl restart system-networkd 如果是桌面版: sudo systemctl restart network-manager |
7、验证 IP 地址
1 |
ip a |
8. 另外注意他的DNS文件不是 /etc/resolv.conf 而是:
1 |
/etc/systemd/resolved.conf |
1 2 3 4 |
DNS=设置的是域名解析服务器的IP地址,这里分别设为8.8.8.8和114.114.114.114 LLMNR=设置的是禁止运行LLMNR(Link-Local Multicast Name Resolution),否则systemd-resolve会监听5535端口。 sudo systemctl restart systemd-resolved |
9 查看DNS
1 |
networkctl status |
- 本文固定链接: https://www.yoyoask.com/?p=3765
- 转载请注明: shooter 于 SHOOTER 发表