cd\
copy con ipdns.bat
netsh interface ip set address name="本地连接" static 192.168.0.252 255.255.255.0 192.168.0.1 1
netsh interface ip add address name="本地连接" static 192.168.11.252 255.255.255.0 192.168.11.1 1
netsh interface ip set dns "本地连接" static 202.106.0.20
Ctrl+z
_____________________________________________
如果你的网络名称不是“本地连接” 改为相应的就行。 11.252那个地址,如果不想设网关可以去掉后面的192.168.11.1那个网关。
可以将ipdns.bat拷到桌面上。每次运行就双击这个批处理就行了。
#!/bin/bash
################################变量定义################################
nameDevice=eth0
ipAdddress=192.168.4.110
prefix=255.255.255.0
netMask=255.255.255.0
gateway=192.168.4.1
dns1=8.8.8.8
dns2=192.168.4.0
################################函数模块################################
##设置NetworkManager服务
function SetNetworkManagerDisable(){
systemctl stop NetworkManager &&systemctl disable NetworkManager &&echo "NetworkManager is stop and disable" &&return 0 || return 1
}
##设置NetworkManager服务
function SetNetworkEnable(){
systemctl restart network &&systemctl enable network &&echo "network is start and enable" &&return 0 || return 1
}
##查看服务器第一个网卡名称
function FindFirstNICName(){
ifconfig|head -n 1|cut -d \: -f 1 &&[ $? == 0 ] &&nameDevice=`ifconfig|head -n 1|cut -d \: -f 1` &&return 0 || return 1
}
##设置服务器网卡IP地址
function SetNICFile(){
cat >/etc/sysconfig/network-scripts/ifcfg-$nameDevice <<EOF
TYPE="Ethernet"
BOOTPROTO="none"
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=$nameDevice
DEVICE=$nameDevice
ONBOOT=yes
IPADDR=$ipAdddress
PREFIX=$prefix
NETMASK=$netMask
GATEWAY=$gateway
DNS1=$dns1
DNS2=$dns2
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_PRIVACY=no
EOF
}
##消除变量
function UnsetVariate(){
unset nameDevice
unset ipAdddress
unset prefix
unset netMask
unset gateway
unset dns1
unset dns2
}
################################程序流程################################
##设置网络服务为network
FindFirstNICName
SetNICFile
SetNetworkEnable
SetNetworkManagerDisable
UnsetVariate
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)