Linux设置默认路由

CentOS7.9

查看网络路由

ip route show|column -t

删除默认路由

ip route del default via 192.168.1.1

添加默认路由

ip route add default via 192.168.1.1 dev eth0

双网卡指定默认路由

vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEFROUTE="yes"

Ubuntu16.04.7

sudo vim /etc/network/interfaces
auto ens3
iface ens3 inet static
address 192.168.1.101
netmask 255.255.255.0
gateway 192.168.1.1

auto ens4
iface ens4 inet dhcp

ip route del default gw 192.168.1.1
ip route add default gw 10.168.1.1

Ubuntu22.04默认网关配置

cat /etc/netplan/00-installer-config.yaml
network:
  ethernets:
    ens3:
      dhcp4: true
    ens4:
      dhcp4: no
      addresses: ["192.168.1.157/22"]
      routes:
        - to: 10.168.1.0/24
          via: 10.168.1.1
      nameservers:
        addresses:
        - 192.168.1.1
  version: 2
posted @ 2022-04-07 17:03  GreeneGe  阅读(4691)  评论(0编辑  收藏  举报

https://github.com/Glf9832