为主机配置IP

第一种方法:nmcli

#nmcli connection modify eth0 ipv4.method manual ipv4.addresses 172.25.254.100/24 ipv4.gateway 172.25.254.2 ipv4.dns 114.114.114.114 autoconnect yes
#nmcli c up etho   //激活网卡命令(网卡早就配好,只是修改ip就不用输入这条命令了)

 

第二种方法:网卡可视化界面 

#nm-connection-editor

起一个网卡名称

写上IP、掩码、网关、dns服务器地址 

也可以在Method选择DHCP服务自动获取

 选择这块网卡

 有IP且可以联网了

第三种方法:shell脚本命令

vim /bin/xxx.sh

起一个shell脚本。

写入

#!/bin/bash                                 'shell执行'
hostnamectl hostname yyy$1.wxrd.org      '$1代表值'
cd /etc/NetworkManager/system-connections/
rm -fr *                                     '这条命令千万不要在服务器上用!后果很严重'
cat > eth0.nmconnection <<EOF
[connection]
id=eth0
type=ethernet
interface-name=eth0

[ipv4]
method=manual
addressl=192.168.1.$1/24,192.168.1.2      'IP/掩码,网关;自行定义网段;网关用route-n命令查'
dns=114.114.114.114;                      '自行定义'

EOF

chmod 600 eth0.nmconnection                  '赋予可执行权限'

nmcli connection reload
nmcli connection up eth0

echo "192.168.1.$1  server$1.wxrd,org" >> /etc/hosts
#chmod +x /bin/xxx.sh                         '赋予文件可执行权限‘

 这样,就可以用了(这台放起来)

克隆出一个他的克隆虚拟机

#xxx.sh 100                                 '执行'

这台名称为yyy100.wxrd.org 且IP地址为192.168.1.100/24的主机诞生啦

证明脚本设定好啦!

以上三种设置IP的方法

拜拜-----------------------------------------------------------------------------------------------------(疯狂尖叫)

  • 6
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值