ubuntu1804配置静态IP

在ubuntu1804系统做开发时,我们需要配置静态IP,方便开发调试,本篇介绍在虚拟机中的Ubuntu1804配置静态IP。

首先我们用ifconfig命令查看网口信息

这里的192.168.31.229是动态分配的,关机下次再开机就会变化。

打开配置文件

sudo vim /etc/netplan/01-network-manager-all.yaml

在设置里打开

 

保存重启系统

可以联网

sudo vim /etc/netplan/01-network-manager-all.yaml

这种设置并没有保存到配置文件中。

XShell连接不上。

静态配置,打开配置文件

scott@ubuntu1804:~$ sudo vim /etc/netplan/01-network-manager-all.yaml

xshell连接

没装ssh

scott@ubuntu1804:~$ sudo apt-get install ssh
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  ncurses-term openssh-client openssh-server openssh-sftp-server ssh-import-id
Suggested packages:
  keychain libpam-ssh monkeysphere ssh-askpass molly-guard rssh
The following NEW packages will be installed:
  ncurses-term openssh-server openssh-sftp-server ssh ssh-import-id
The following packages will be upgraded:
  openssh-client
1 upgraded, 5 newly installed, 0 to remove and 91 not upgraded.
Need to get 1,252 kB of archives.
After this operation, 5,427 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-updates/main amd64 openssh-client amd64 1:7.6p1-4ubuntu0.7 [610 kB]
Get:2 http://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-updates/main amd64 openssh-sftp-server amd64 1:7.6p1-4ubuntu0.7 [45.5 kB]
Get:3 http://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-updates/main amd64 openssh-server amd64 1:7.6p1-4ubuntu0.7 [332 kB]
Get:4 http://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-updates/main amd64 ssh all 1:7.6p1-4ubuntu0.7 [5,192 B]
Get:5 http://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-updates/main amd64 ncurses-term all 6.1-1ubuntu1.18.04.1 [248 kB]
Get:6 http://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-updates/main amd64 ssh-import-id all 5.7-0ubuntu1.1 [10.9 kB]
Fetched 1,252 kB in 1s (974 kB/s)        
Preconfiguring packages ...
(Reading database ... 175347 files and directories currently installed.)
Preparing to unpack .../0-openssh-client_1%3a7.6p1-4ubuntu0.7_amd64.deb ...
Unpacking openssh-client (1:7.6p1-4ubuntu0.7) over (1:7.6p1-4ubuntu0.5) ...
Selecting previously unselected package openssh-sftp-server.
Preparing to unpack .../1-openssh-sftp-server_1%3a7.6p1-4ubuntu0.7_amd64.deb ...
Unpacking openssh-sftp-server (1:7.6p1-4ubuntu0.7) ...
Selecting previously unselected package openssh-server.
Preparing to unpack .../2-openssh-server_1%3a7.6p1-4ubuntu0.7_amd64.deb ...
Unpacking openssh-server (1:7.6p1-4ubuntu0.7) ...
Selecting previously unselected package ssh.
Preparing to unpack .../3-ssh_1%3a7.6p1-4ubuntu0.7_all.deb ...
Unpacking ssh (1:7.6p1-4ubuntu0.7) ...
Selecting previously unselected package ncurses-term.
Preparing to unpack .../4-ncurses-term_6.1-1ubuntu1.18.04.1_all.deb ...
Unpacking ncurses-term (6.1-1ubuntu1.18.04.1) ...
Selecting previously unselected package ssh-import-id.
Preparing to unpack .../5-ssh-import-id_5.7-0ubuntu1.1_all.deb ...
Unpacking ssh-import-id (5.7-0ubuntu1.1) ...
Setting up ncurses-term (6.1-1ubuntu1.18.04.1) ...
Setting up openssh-client (1:7.6p1-4ubuntu0.7) ...
Setting up ssh-import-id (5.7-0ubuntu1.1) ...
Setting up openssh-sftp-server (1:7.6p1-4ubuntu0.7) ...
Setting up openssh-server (1:7.6p1-4ubuntu0.7) ...

Creating config file /etc/ssh/sshd_config with new version
Creating SSH2 RSA key; this may take some time ...
2048 SHA256:pRTgPgstlyCCUvgkdYD9js6j7u7oVDwatJwj0c8wskw root@ubuntu1804 (RSA)
Creating SSH2 ECDSA key; this may take some time ...
256 SHA256:Vl6RjwKxY06+yPJLJNlhsaqixoPXN3bTWXk9nZTllfI root@ubuntu1804 (ECDSA)
Creating SSH2 ED25519 key; this may take some time ...
256 SHA256:eoXAy8/DwSjZPbVAt5uQMxLOBXMnxWlwmmIu0QxyC24 root@ubuntu1804 (ED25519)
Created symlink /etc/systemd/system/sshd.service → /lib/systemd/system/ssh.service.
Created symlink /etc/systemd/system/multi-user.target.wants/ssh.service → /lib/systemd/system/ssh.service.
Setting up ssh (1:7.6p1-4ubuntu0.7) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for ufw (0.36-0ubuntu0.18.04.1) ...
Processing triggers for ureadahead (0.100.0-21) ...
Processing triggers for systemd (237-3ubuntu10.57) ...
scott@ubuntu1804:~$ 

 再次连接

输入用户名和密码

连接正常

参考:

虚拟机中Ubuntu1804 Server 配置静态IP_ubuntu1804配置静态ip-CSDN博客

Ubuntu18.04的网络配置(静态IP和动态IP) - OpsDrip - 博客园 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值