今天嘗試在hyper-v設定ubuntu固定IP,不想IP是可以浮動,導致SSH的麻煩
作了以下操作
sudo vi /etc/netplan/50-cloud-init.yaml
network:
ethernets:
eth0:
addresses: [192.168.137.200/24]
sudo netplan apply
之後ifconfig 數據如下
使用SSH連接出現錯誤
Connecting to 192.168.137.200:22...
Could not connect to '192.168.137.200' (port 22): Connection failed.
請問我哪邊做錯了嗎?
更新
嘗試1 : 將50-cloud-init.yaml
檔案清空保存
結果 : 可以正確連線,但又變回浮動IP
...
Connecting to 172.25.60.31:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Welcome to Ubuntu 20.04.1 LTS (GNU/Linux 5.4.0-47-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Mon 14 Sep 2020 03:00:05 AM UTC
System load: 0.0 Processes: 126
Usage of /: 8.1% of 61.76GB Users logged in: 1
Memory usage: 17% IPv4 address for docker0: 172.17.0.1
Swap usage: 0% IPv4 address for eth0: 172.25.60.31
30 updates can be installed immediately.
0 of these updates are security updates.
To see these additional updates run: apt list --upgradable
Last login: Mon Sep 14 02:11:39 2020 from 172.25.48.1
test@test:~$
嘗試 : 按照 wrxue 大神做法
看你使用浮動IP的結果,你的介面卡eth0網段應該是172.25.48.0/20,你設定一個192.168.137.200/24當然不會通
network:
ethernets:
eth0:
addresses: [172.25.60.31/24]
結果 : 可以正常SSH連線!
Connecting to 172.25.60.31:22...
Connection established.
看你使用浮動IP的結果,你的介面卡eth0
網段應該是172.25.48.0/20
,你設定一個192.168.137.200/24
當然不會通
也許你可以實驗
172.25.60.31/20
寫到50-cloud-init.yaml,確定能連線172.25.60.32/20
,確定能連線192.168.137.200/24
,確定不能連線,就是網段問題若連第一步都無法連線,就肯定是哪裡設定錯了