Linux Network scripts
来源:互联网 发布:java怎么调用二维码 编辑:程序博客网 时间:2024/06/06 16:59
local dhcp_ip=`/sbin/ifconfig eth0 | grep 'inet addr' | awk -F: '{print $2}' | awk '{print $1}'`
local dhcp_netmask=`ifconfig eth0 | grep 'inet addr' | awk -F: '{print $NF}'`
local dhcp_dns=`grep nameserver /etc/resolv.conf | head -1 | awk '{print $2}'`
local dhcp_hostname=`/bin/hostname`
local dhcp_gw=`/sbin/ip route show |grep default | awk '{print $3}'`
##Configure DNS
echo -n "search " >>/etc/resolv.conf
echo "$static_hostname" |cut -d '.' -f 2->>/etc/resolv.conf
echo "nameserver $static_dns">>/etc/resolv.conf
# overwite ifcfg-eth0 with static ip setting.
cat > /etc/sysconfig/network-scripts/ifcfg-eth0 <<-EOF
DEVICE=eth0
ONBOOT=yes
TYPE=Ethernet
IPADDR=$static_ip
NETMASK=$static_netmask
PEERDNS=no
EOF
cat > /etc/sysconfig/network <<-EOF
NETWORKING=yesHOSTNAME=$static_hostname
GATEWAY=$static_gw
EOF
echo "Restarting networking..."
echo
service network restart
hostname $static_hostname
}
#function: update /etc/hosts file
#parameter:
#return
function fix_hosts {
local host_name=`hostname`
local host_name_s=`echo $host_name|awk -F. '{print $1}'`
local ips=`ifconfig -a | grep -v "127.0.0.1" | grep 'inet addr' | awk -F: '{print $2}' | awk '{print $1}'`
for ip in $ips; do
if [ "x$ip" != "x" ];then
sed -i "/$ip/d" /etc/hosts
echo "$ip $host_name $host_name_s" >> /etc/hosts
fi
done
}
#function: check if the IP address is valid
#parameter:
#return: 1 if the IP address is invalid
#note: in the if or while , the 1 equal to false
function check_ip {
if ! ifconfig -a | grep "inet addr" |grep -q -v "127.0.0.1";
then
return 1
fi
}
#function: check if the hostname is valid
#parameter:
#return: 1 if the IP hostname is invalid
#note: in the if or while , the 1 equal to false
function check_hostname {
local host_name=`hostname`
if [ "x$host_name" = "xlocalhost.localdomain" ]
then
return 1
fi
if ! hostname -i>/dev/null 2>&1
then
return 1
fi
}
- Linux Network scripts
- linux /etc/sysconfig/network-scripts/
- Linux Scripts
- 自动修改linux下/etc/sysconfig/network-scripts/ifcfg-ethX网卡文件的脚本
- linux中网络配置文件/eth/sysconfig/network-scripts/ifcfg-ethX以及ifup|ifdown小结
- linux在/etc/sysconf/network-scripts/ifcfg-DEVICE修改ip地址
- Linux /etc/sysconfig/network-scripts中ifcfg-eth0 网卡配置没有IPADDR配置IP属性
- 配置/etc/sysconfig/network-scripts/ifcfg-ethx
- 2015-12-23 QEMU Network Scripts
- 有关/etc/sysconfig/network-scripts/ifcfg-eth0
- /etc/sysconfig/network-scripts下文件
- linux shell scripts
- 【Linux】bash shell scripts
- LINUX(4) shell scripts
- Linux学习笔记 --Bash Scripts
- 弄丢了/etc/sysconfig/network-scripts/ifcfg-eth0 文件
- 配置/etc/sysconfig/network-scripts/ifcfg-ethx [ IPV4篇 ]
- 配置/etc/sysconfig/network-scripts/ifcfg-ethx [ IPV6篇 ]
- sigaction()
- 【汇总】存储过程、触发器 资料
- 避免使用宏
- 什么是REST?以及RESTful的实现
- 单链表是否有环并如何找到环入口
- Linux Network scripts
- 做足这5点,老板立马会对你另眼相看
- union:一种实用的共用体用法
- 管理团队的心理绝招
- 在linux下为mysql开启更新日志
- 让UIWebView根据内容自动调整高度
- 常用js函数CheckData.js
- lua loadlib函数 attempt to call global 'loadlib' (a nil value)
- 千年潜规则一语道破