0
点赞
收藏
分享

微信扫一扫

linux下配置/etc/hosts脚本

凌得涂 2023-01-13 阅读 57

2012-03-11
#!/bin/bash
IP=$(ifconfig bond0 | grep 'inet addr:' |awk -F ":" '{print $2}' |awk '{print $1}') //提取IP地址,并给变量赋值
sed -i '1i'$IP'' /etc/hosts //将变量IP插入到/etc/hosts第一行
sed -i '/^'$IP'.*$/s//& '$HOSTNAME'/g' /etc/hosts //在IP后面插入主机名
sed -i '3{s/^/#/}' /etc/hosts //注释掉IPV6

举报

相关推荐

0 条评论