Windows、Linux添加路由

目录

一、Windows添加路由

[1. 查看路由规则](#1. 查看路由规则)

[2. 添加路由规则](#2. 添加路由规则)

[3. 添加默认路由](#3. 添加默认路由)

[4. 删除路由规则](#4. 删除路由规则)

二、Linux添加路由

[1. 查看路由](#1. 查看路由)

[2. 添加路由](#2. 添加路由)

[3. 删除路由](#3. 删除路由)

[4. 修改路由](#4. 修改路由)

[5. 临时路由](#5. 临时路由)

[6. 默认网关设置](#6. 默认网关设置)


一、Windows添加路由

1. 查看路由规则

bash 复制代码
route print

2. 添加路由规则

bash 复制代码
route add -p $目标网段 mask $netmask $gateway

route add -p $目标网段 mask $netmask $gateway

3. 添加默认路由

bash 复制代码
#添加默认路由,metric为优先级(值越大,优先级越低)
route add -p 0.0.0.0 mask 0.0.0.0 $gateway metric 10

4. 删除路由规则

bash 复制代码
#删除路由规则
route delete $目标网段 mask $netmask

二、Linux添加路由

1. 查看路由

bash 复制代码
ip route show
或
route -n

2. 添加路由

bash 复制代码
ip route add [destination] via [gateway] dev [interface]
或
route add -net [network_address] netmask [netmask] gw [gateway_ip] dev [interface]

# 示例
ip route add 192.168.2.0/24 via 192.168.1.1 dev eth0

3. 删除路由

bash 复制代码
# 删除路由
ip route del [destination]
或
route del -net [network_address] netmask [netmask] gw [gateway_ip]

# 示例
ip route del 192.168.2.0/24

4. 修改路由

bash 复制代码
# 修改路由
ip route change [destination] via [new_gateway] dev [interface]

5. 临时路由

bash 复制代码
# 临时路由(直到重启或清除)
ip route add [destination] via [gateway] dev [interface] temporary

6. 默认网关设置

bash 复制代码
# 默认网关设置
ip route add default via [gateway_ip] dev [interface]
相关推荐
阿里云大数据AI技术6 小时前
阿里云 EMR AI 助手正式发布:从问答工具到全栈智能运维助手
运维·人工智能
你好潘先生12 小时前
别再记命令了,用 yeero do 说句人话就能跑脚本,而且不烧 token
服务器·python·命令行
orion571 天前
Missing Semester Class1:course overview and introduction of shell
linux
SkyWalking中文站1 天前
认识 Horizon UI · 6/17:Trace 探索器
运维·监控·自动化运维
用户120487221611 天前
Linux驱动编译与加载
linux·嵌入式
程序员老赵1 天前
服务器文件不想 SFTP 上传?Docker 跑个 File Browser,浏览器就能管理
服务器·docker·开源
火车叼位1 天前
写给初级开发者:SSL、SSH、HTTPS 与证书体系全解析
运维
vivo互联网技术1 天前
从 10 分钟到 1 秒:ES 深度分页任意跳页的三轮优化实战
服务器·数据库·redis·elasticsearch·深度分页
用户805533698031 天前
Input 子系统架构:Core、Handler、Driver 三层是怎么协作的
linux·嵌入式