如何通过命令修改IP地址
# 问题描述
经常需要切换两个本地ip,每次都是打开网络设置改太麻烦了,想要写个脚本一键切换。
# 核心命令
networksetup -setmanual "Ethernet" 192.168.128.54 255.255.255.0 192.168.128.1
# 切换脚本
#!/bin/bash
ips=("192.168.130.167" "192.168.143.242")
gate="192.168.143.254"
next_ip=${ips[0]}
current_ip=(`ipconfig getifaddr en0`)
if [ "${current_ip}" == ${next_ip} ]; then next_ip=${ips[1]}; fi
networksetup -setmanual "Wi-Fi" ${next_ip} 255.255.255.0 ${gate}
echo "${current_ip} => ${next_ip}"
仓库地址:https://github.com/saltbo/devenv/blob/master/shell/ipsw.sh
# 参考内容
- https://blog.csdn.net/u010953692/article/details/79752715
- 原文出处:
- 原文作者: https://github.com/saltbo
- 原文链接:
- 版权声明:本文欢迎任何形式转载,转载时完整保留本声明信息(包含原文链接、原文出处、原文作者、版权声明)即可。本文后续所有修改都会第一时间在原始地址更新。