时间:2021-05-22
代码一
ubuntu与centos
复制代码 代码如下:
ubuntu:
#!/bin/bash
echo "ipaddr:"
read line
echo $line
sed "s/address.*$/address=${line}/g" /etc/network/interfaces
centos(未测试):
#!/bin/bash
echo "ipaddr:"
read line
echo $line
sed "s/IPADDR.*$/IPADDR=${line}/g" /etc/sysconfig/network-scipts/ifcfg-eth0
代码二
ubuntu更改IP的shell代码,自己写的,比较拙,请指正
复制代码 代码如下:
#! /bin/sh
echo "Use gateway at 192.168.0.1 (Y) or 192.168.1.1 (N)
or detail set (O)\nPlease choose Y/N/O"
read OP
if [ "$OP" = Y ] || [ "$OP" = y ] ; then
GATEWAY=192.168.0.1
IP=192.168.0.215
elif [ "$OP" = N ] || [ "$OP" = n ] ; then
GATEWAY=192.168.1.1
IP=192.168.1.215
else
echo "Please input the ip:"
read IP
echo "Please input the gateway"
read GATEWAY
fi
echo "auto lo
iface lo inet static
auto eth0
iface eth0 inet static
netmask 255.255.255.0
address $IP
gateway $GATEWAY" > /tmp/interfaces
clear
echo "Init File interfaces Successfully!"
echo "*************************************"
cat /tmp/interfaces
echo "*************************************"
echo "Change the file in /etc/networks/interfaces?(Y/N)"
read OP
if [ "$OP" = Y ] || [ "$OP" = y ] ; then
echo "Set OK!"
cp /tmp/interfaces /etc/network/interfaces
/etc/init.d/networking restart
else
echo "Give up"
fi
rm /tmp/interfaces
echo "Whether change the DNS(/etc/resolv.conf)(Y/N)"
read OP
if [ "$OP" = Y ] || [ "$OP" = y ];then
echo "Input the DNS server IP:"
read IP
echo "Now change the DNS IP"
mv /etc/resolv.conf /etc/resolv.conf.bak
echo "nameserver $IP" >/etc/resolv.conf
echo "Done!"
fi
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
之前有的朋友问我,CentOS版本怎么安装python的pip,我之前给出的Ubuntu下apt-get的方法ubuntu需要先安装下pip吧,复制代码代码如下
这篇文章里我们主要分享了python中shell根据ip获取hostname或根据hostname获取ip的代码,具体介绍如下。笔者有时候需要根据hostnam
举个例子吧Django最佳实践与部署:Nginx+Gunicorn+Supervisor(Ubuntu和CentOS)http://sfdye.com/arti
平常工作中,常常会用到Ubuntu,有时候会遇到Ubuntu怎么更换修改左侧图标按钮的大小的问题。那么,Ubuntu怎么更换修改左侧图标按钮的大小呢?下面做一个
使用shell校验IP地址合法性使用方法:复制代码代码如下:[root@yangpython]#bashcheck_ip.shIP地址执行结果:返回值0校验合法