Ubuntu18.04 设置ip地址

1. 自己用vCenter安装了一个ubuntu18.04, 结果因为是 vCenter6.7 只有web界面, 发现GUI操作时鼠标位置不对,没办法只能通过cli的方式设置ip地址.

2. 先简单查看一下虚拟机的ip地址,然后通过ssh连接上去.

这里面有一点ubuntu 默认不允许root用户登录 需要修改

/etc/ssh/sshd.config 的permitrootlogin 设置为 yes 然后重启一下sshd的服务就可以了

并且ubuntu 也可以说使用systemd 作为服务管理了 可以直接使用. systemctl restart  sshd的方式进行重启服务.

3. 简单设置

3.1 设置ip地址

先通过 ifconfig 获取到网卡信息.

 可以比较简单的看到网卡的信息

然后修改配置文件

vim /etc/network/interfaces
添加内容:
注意网卡设备要选择好
auto ens160 iface ens160 inet
static address 10.24.22.150 gateway 10.24.255.254 netmask 255.255.0.0 dns-nameservers 10.100.1.11

3.2 发现设置完ip地址虽然有 dns-servers的设置 但是依旧无法连通网络无法 apt安装东西.

然后需要修改 dns的设置

vim /etc/systemd/resolved.conf

在里面增加好内容
[Resolve]
DNS=10.100.1.11


重启一下服务 或者是重启一下机器就好. 
  
systemctl restart systemd-resolved

3.3 验证可以访问域名网络

root@pscloud:/etc# systemctl restart systemd-resolved
root@pscloud:/etc# ping www.163.com
PING z163ipv6.v.bsgslb.cn (218.92.152.19) 56(84) bytes of data.
64 bytes from 218.92.152.19 (218.92.152.19): icmp_seq=1 ttl=53 time=30.2 ms
64 bytes from 218.92.152.19 (218.92.152.19): icmp_seq=2 ttl=53 time=29.9 ms
64 bytes from 218.92.152.19 (218.92.152.19): icmp_seq=3 ttl=53 time=29.9 ms
64 bytes from 218.92.152.19 (218.92.152.19): icmp_seq=4 ttl=53 time=30.0 ms

猜你喜欢

转载自www.cnblogs.com/jinanxiaolaohu/p/12111458.html