Ubuntu18.04使用的网络管理是netplan, 配置文件在/etc/netplan/下
刚安装完成的配置是这样的(设置成了静态IP, 添加了DNS)
network:
ethernets:
ens3:
addresses:
- 192.168.13.25/24
dhcp4: false
gateway4: 192.168.13.1
nameservers:
addresses:
- 114.114.114.114
search: []
version: 2
添加静态路由
network:
ethernets:
ens3:
addresses:
- 192.168.13.25/24
dhcp4: false
gateway4: 192.168.13.1
nameservers:
addresses:
- 114.114.114.114
search: []
routes:
- to: 10.8.0.0/24
via: 192.168.13.15
version: 2
查看配置结果
sudo networkctl status -a
Ubuntu18.04自带了一个简单防火墙工具 UFW(Uncomplicated Firewall), 职能与firewalld类似, UFW实际上底层起作用的还是是iptables.
默认情况下UFW 阻止所有传入连接并允许所有传出连接. 任何尝试访问当前机器的请求都无法连接, 但当前机器上运行的应用能对外访问.
sudo ufw enable
sudo ufw disable
sudo ufw status verbose
sudo ufw app list
sudo ufw app info OpenSSH
添加开放端口的几种方式
5. 允许ssh连接(根据app配置打开22端口)
sudo ufw allow OpenSSH
sudo ufw allow http
sudo ufw allow 80
sudo ufw allow 80/tcp
sudo ufw allow 'Nginx HTTP'
sudo ufw allow https
sudo ufw allow 443/tcp
sudo ufw allow 'Nginx HTTPS'
ufw allow 11200:11299/tcp
ufw allow from 192.168.0.0/16 to any port 5001
ufw allow proto tcp from 10.0.0.0/8 to 192.168.0.1 port 25
sudo ufw allow from 192.168.0.0/16
添加拒绝端口
17. both tcp and udp
sudo ufw deny 53
sudo ufw deny 53/tcp
删除存在的规则
sudo ufw delete deny 80/tcp
sudo ufw delete allow 53/udp