123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- #!/bin/bash
- set -e
- function usage() {
- echo -e "USAGE:
- $(basename $0) --help # 使用帮助
- $(basename $0) wifi # 连接wifi
- $(basename $0) pxe # pxe IP
- $(basename $0) work1 # 工作 IP 1
- $(basename $0) work2 # 工作 IP 2
- $(basename $0) work3 # 黄河大厦 172.29.157.20
- "
- exit 1
- }
- # 判断参数个数
- if [ $# -eq 0 ]; then
- usage
- exit 1
- fi
- IFACE_LAN=$(LANG=en ip link | awk -F '[ :]' '{print $3}' | grep "^e")
- echo "IFACE_LAN=${IFACE_LAN}"
- if [ "$1" == "wifi" ]; then
- WIFI_SSID=kylin-gcjs-zz
- if nmcli device wifi list | grep -q ${WIFI_SSID}; then
- nmcli dev wifi connect ${WIFI_SSID} password gcjsqwe123
- fi
- exit
- elif [ "$1" == "work1" ]; then
- IPADDR=172.29.220.241
- GATEWAY=172.29.221.254
- DNS1=114.114.114.114
- DNS2=172.20.191.2
- elif [ "$1" == "work2" ]; then
- IPADDR=172.29.220.242
- GATEWAY=172.29.221.254
- DNS1=114.114.114.114
- DNS2=172.20.191.2
- elif [ "$1" == "work3" ]; then
- IPADDR=172.29.157.20
- GATEWAY=172.29.157.254
- DNS1=114.114.114.114
- DNS2=172.20.191.2
- elif [ "$1" == "pxe" ]; then
- IPADDR=10.0.0.10
- GATEWAY=10.0.0.1
- DNS1=10.0.0.10
- DNS2=114.114.114.114
- elif [ "$1" == "242" ]; then
- IPADDR=172.29.220.242
- GATEWAY=172.29.220.242
- DNS1=172.29.220.242
- DNS2=114.114.114.114
- elif [ "$1" == "dhcp" ]; then
- echo "自动分配"
- fi
- if [ ! -s $IPADDR ]; then
- # nmcli c modify "有线连接 1" ifname ${IFACE_LAN} ipv4.method manual ipv4.addr ${IPADDR}/16 ipv4.gateway ${GATEWAY} ipv4.dns "${DNS1},${DNS2}"
- nmcli c modify "有线连接 1" ifname ${IFACE_LAN} ipv4.method manual ipv4.addr ${IPADDR}/24 ipv4.gateway ${GATEWAY} ipv4.dns "${DNS1},${DNS2}"
- nmcli c up "有线连接 1"
- fi
|