mac上添加路由配置

前言

特殊场景下,需要添加网络的路由

操作

在 Mac 上,可以使用 route 命令来添加静态路由。命令格式如下:

shell 复制代码
sudo route add -net [目标网络] -netmask [子网掩码] -interface [网络接口] -gateway [网关IP]

例如在linux服务器上 添加 路由配置

shell 复制代码
ip route add 10.233.12.0/18 via 192.168.10.100

在 Mac 上的等价命令为:

shell 复制代码
sudo route add -net 10.233.12.0 -netmask 255.255.192.0 -interface [网络接口] -gateway 192.168.10.100

其中 网络接口 需要替换为你的实际网络接口名称,可以使用 networksetup -listallhardwareports 命令查看。通常情况下,有线网络接口名为 en0,无线网络接口名为 en1。

例如,如果你要通过有线网络接口 en0 添加上述两条路由,命令应该是:

shell 复制代码
sudo route add -net 10.233.12.0 -netmask 255.255.192.0 -interface en0 -gateway 192.168.10.100

添加完成后,你可以使用 netstat -rn 命令查看路由表,确认路由已经添加成功。

需要注意的是,这些路由是临时的,重启系统后会丢失。如果你需要永久保存路由,可以将这些命令添加到 /etc/rc.local 文件中,该文件在系统启动时会自动执行。


the end !!!

good day !!!

相关推荐
寒水馨2 小时前
macOS下载、安装PowerShell-v7.6.4(附安装包powershell-7.6.4-osx-arm64.pkg)
macos·自动化·跨平台·shell·脚本·命令行·powershell
弹简特9 小时前
【Vue3速成】05-vue3官方库路由机制之路由守卫
vue·路由
星辰即远方21 小时前
天气预报总结
macos·ios·objective-c·cocoa
xixiaoyunya21 小时前
Mac远程访问新范式:基于80KM穿云箭的内网穿透技术实践
macos
秋雨梧桐叶落莳1 天前
计算器仿写总结
学习·macos·ios·objective-c·cocoa
寒水馨1 天前
macOS下载、安装uv-0.12.0(附安装包uv-aarch64-apple-darwin.tar.gz)
python·macos·rust·项目管理·包管理器·astral·pip替代
寒水馨1 天前
macOS下载、安装protobuf-v35.1(附安装包protoc-35.1-osx-universal_binary.zip)
macos·google·grpc·序列化·protobuf·protoc·数据交换
寒水馨1 天前
macOS下载、安装ripgrep-15.2.0(附安装包ripgrep-15.2.0-aarch64-apple-darwin.tar.gz)
macos·正则表达式·rust·ripgrep·rg·命令行搜索·代码搜索
起司喵喵2 天前
Flutter-MacOS桌面OS系统|flutter.+window_manager客户端OS模板
flutter·macos·策略模式
代码对我眨眼睛2 天前
macOS Google Chrome 常用快捷键
前端·chrome·macos