欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Linux配置静态路由

程序员文章站 2022-03-01 17:01:56
...

1. Ubuntu16

# cat /etc/network/interfaces
auto lo
iface lo inet loopback

auto ens33
iface ens33 inet static
...
up route add -net 192.168.1.0 netmask 255.255.255.0 gw 10.0.0.4 dev ens33
$ sudo /etc/init.d/networking restart

2. Ubuntu20

$ cat /etc/netplan/01-network-manager-all.yaml 
# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager
  ethernets:
    eno1:
      ...
      routes:
      - to: 192.168.1.0/24
        via: 10.0.0.4
$ sudo netplan apply
$ ip route show
...
192.168.1.0/24 via 10.0.0.4 dev eno1 proto static metric 100 
...
相关标签: Linux 路由