如何通过主机从外部 SSH 到 VirtualBox 来宾?

发布于 2024-11-05 20:44:59 字数 1549 浏览 1 评论 0 原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(15

总以为 2024-11-12 20:44:59

登录来宾 Linux VirtualBox VM 的最佳方式是端口转发。默认情况下,您应该已经有一个使用 NAT 的接口。然后转到“网络”设置并单击“端口转发”按钮。添加新的规则。作为规则名称,插入“ssh”。作为“主机端口”,插入 3022。作为“访客端口”,插入 22。规则的其他所有内容都可以留空。

或从命令行

VBoxManage modifyvm myserver --natpf1 "ssh,tcp,,3022,,22"

,其中“myserver”是创建的虚拟机的名称。检查添加的规则:

VBoxManage showvminfo myserver | grep 'Rule'

仅此而已!请确保您不要忘记在虚拟机中安装 SSH 服务器:

sudo apt-get install openssh-server

通过 SSH 进入来宾 VM,写入:

ssh -p 3022 [email protected]

其中 user 是您在 VM 中的用户名。

The best way to login to a guest Linux VirtualBox VM is port forwarding. By default, you should have one interface already which is using NAT. Then go to the Network settings and click the Port Forwarding button. Add a new Rule. As the rule name, insert "ssh". As "Host port", insert 3022. As "Guest port", insert 22. Everything else of the rule can be left blank.

or from the command line

VBoxManage modifyvm myserver --natpf1 "ssh,tcp,,3022,,22"

where 'myserver' is the name of the created VM. Check the added rules:

VBoxManage showvminfo myserver | grep 'Rule'

That's all! Please be sure you don't forget to install an SSH server in the VM:

sudo apt-get install openssh-server

To SSH into the guest VM, write:

ssh -p 3022 [email protected]

Where user is your username within the VM.

俏︾媚 2024-11-12 20:44:59

将 VirtualBox 中的适配器类型更改为桥接,并将来宾设置为使用 DHCP 或设置静态 < a href="http://en.wikipedia.org/wiki/IP_address" rel="noreferrer">IP 地址 超出 DHCP 范围。这将使虚拟机像家庭网络上的普通访客一样工作。然后您可以转发。

Change the adapter type in VirtualBox to bridged, and set the guest to use DHCP or set a static IP address outside of the bounds of DHCP. This will cause the Virtual Machine to act like a normal guest on your home network. You can then port forward.

囍笑 2024-11-12 20:44:59

保留 NAT 适配器并添加第二个仅主机适配器效果惊人,并且对于笔记本电脑(外部网络总是发生变化)至关重要。

http://muffinresearch。 co.uk/archives/2010/02/08/howto-ssh-into-virtualbox-3-linux-guests/

记住创建virtualbox 本身中的仅主机网络(GUI -> 设置 -> 网络),否则您无法在来宾上创建仅主机接口。

Keeping the NAT adapter and adding a second host-only adapter works amazing, and is crucial for laptops (where the external network always changes).

http://muffinresearch.co.uk/archives/2010/02/08/howto-ssh-into-virtualbox-3-linux-guests/

Remember to create a host-only network in virtualbox itself (GUI -> settings -> network), otherwise you can't create the host-only interface on the guest.

寂寞陪衬 2024-11-12 20:44:59

您还可以在网络设置中使用桥接网络(或较新版本中的“桥接适配器”)。这会将您的虚拟机与您的计算机置于一个 VLAN 中。所以你可以像这样通过 ssh 进入虚拟机。

ssh 用户@IP_OF_VM

You can also use a Bridged Network (or "Bridge Adapter", in newer versions) in network settings. This will put your VM in a VLAN with your machine. So you can just ssh into the VM like this.

ssh user@IP_OF_VM

晨曦÷微暖 2024-11-12 20:44:59

如何为 Solaris 10 和 Ubuntu 16.04 创建仅主机网络(比桥接更好

添加仅主机接口

  1. Virtualbox >文件>首选项>网络>仅主机网络>添加
  2. 关闭虚拟机。
  3. 虚拟机设置>网络。第一个适配器应该是 Nat,第二个适配器应该是 Host-only。
  4. 启动 cmd.exe 并运行 ipconfig /all。您应该看到以下几行:

    以太网适配器 VirtualBox Host-Only 网络:
       ...
       IPv4 地址。 。 。 。 。 。 。 。 。 。 。 :192.168.59.1
    

    来宾中的第二个适配器也应位于 192.168.59.*。

  5. 启动虚拟机。

Solaris 10

  1. 检查设置 ifconfig -一个。您应该看到 e1000g0 和 e1000g1。我们对 e1000g1 感兴趣。
  2. ifconfig e1000g down
  3. ifconfig e1000g 192.168.56.10 netmask 255.255.255.0 up
  4. 从主机检查此接口是否可访问:ping 192.168.56.10

保留这些设置重新启动后

# vi /etc/hostname.e1000g1
192.168.56.10 netmask 255.255.255.0
# reboot

配置 ssh 服务 (管理)以root身份登录(不建议)

检查是否启用了ssh

# svcs -a | grep ssh
online         15:29:57 svc:/network/ssh:default

修改/etc/ssh/sshd_config以便有

PermitRootLogin yes

重新启动ssh服务

svcadm restart ssh

从主机检查

ssh [email protected]

Ubuntu 16.04

列表接口:

ip addr

你应该看到三个接口,如 lo、enp0s3、enp0s8。我们将使用第三个。

编辑 /etc/network/interfaces

auto enp0s8
iface enp0s8 inet static
    address 192.168.56.10
    netmask 255.255.255.0

然后sudo ifup enp0s8。检查 enp0s8 是否获得正确的地址。您应该看到您的 IP:

 $ ip addr show enp0s8
 ...
    inet 192.168.56.10/24 brd 192.168.56.255 scope global secondary enp0s8

如果没有,您可以运行 sudo ifdown enp0s8 && sudo ifup enp0s8

https://superuser.com/questions/424083 /virtualbox-host-ssh-to-guest/424115#424115

How to do host-only network (better than bridged) for Solaris 10 and Ubuntu 16.04

Add Host-only interface

  1. Virtualbox > File > Preferences > Network > Host-only Networks > Add
  2. Shutdown vm.
  3. VM's Settings > Network. First adapter should be Nat, second Host-only.
  4. Start cmd.exe and run ipconfig /all. You should see lines:

    Ethernet adapter VirtualBox Host-Only Network:
       ...
       IPv4 Address. . . . . . . . . . . : 192.168.59.1
    

    Second adapter in guest should also be in 192.168.59.*.

  5. Start VM.

Solaris 10

  1. Check settings ifconfig -a. You should see e1000g0 and e1000g1. We are interested in e1000g1.
  2. ifconfig e1000g down
  3. ifconfig e1000g 192.168.56.10 netmask 255.255.255.0 up
  4. Check from host if this interface is reachable: ping 192.168.56.10

Preserve those settings upon reboot

# vi /etc/hostname.e1000g1
192.168.56.10 netmask 255.255.255.0
# reboot

Configure ssh service (administering) to login as root (not adviced)

Check if ssh is enabled

# svcs -a | grep ssh
online         15:29:57 svc:/network/ssh:default

Modify /etc/ssh/sshd_config so there is

PermitRootLogin yes

Restart ssh service

svcadm restart ssh

From host check it

ssh [email protected]

Ubuntu 16.04

List interfaces:

ip addr

You should see three interfaces like lo, enp0s3, enp0s8. We will use the third.

Edit /etc/network/interfaces

auto enp0s8
iface enp0s8 inet static
    address 192.168.56.10
    netmask 255.255.255.0

Then sudo ifup enp0s8. Check if enp0s8 got correct address. You should see your ip:

 $ ip addr show enp0s8
 ...
    inet 192.168.56.10/24 brd 192.168.56.255 scope global secondary enp0s8

If not, you may run sudo ifdown enp0s8 && sudo ifup enp0s8

https://superuser.com/questions/424083/virtualbox-host-ssh-to-guest/424115#424115

↘人皮目录ツ 2024-11-12 20:44:59

为了从主机通过 ssh 连接到 VirtualBox 中运行的 Ubuntu 虚拟机,您需要为虚拟机设置两个网络适配器。

首先,如果尚未停止,请停止虚拟机。

然后选择虚拟机并单击 VirtualBox 工具栏中的“设置”菜单:

在此处输入图像描述

设置适配器 1

<图片src="https://i.sstatic.net/63znz.png" alt="在此处输入图像描述">

设置适配器 2

在此处输入图像描述

(注意:您不需要设置任何端口转发。)

就是这样。设置完成后,您就可以启动虚拟机了。在您的虚拟机中,网络配置如下所示,并且您也可以访问 Internet:

在此处输入图像描述

另外,在您的主机中,您可以 ssh 到您的虚拟机:

在此处输入图像描述

确保 SSH 服务器已安装并在 VM 中运行。

$ ps aux | grep sshd
root 864 0.1 0.5 65512 5392 ? Ss 22:10 0:00 /usr/sbin/sshd -D

如果没有,请安装它:

$ sudo apt-get install openssh-server

另外供您参考:

  • 我的 VirtualBox 版本:5.2.6 r120293 (Qt5.6.2),2018
  • 我的 Ubuntu 版本:Ubuntu 16.04.3 LTS
  • 我的主机:Windows 10

In order to ssh to a Ubuntu VM running in VirtualBox from your host machine, you need to set up two network adapters for the VM.

First of all, stop the VM if not yet.

Then select the VM and click the Settings menu in the VirtualBox toolbar:

enter image description here

Set up Adapter 1

enter image description here

Set up Adapter 2

enter image description here

(Note: you don't need to set up any port forwarding.)

That's it. Once set up, you can start your VM. In your VM, the network configuration will look like below and you'll have Internet access too:

enter image description here

Also in your host machine, you can ssh to your VM:

enter image description here

Be sure that the SSH server has been installed and up running in the VM.

$ ps aux | grep sshd
root 864 0.1 0.5 65512 5392 ? Ss 22:10 0:00 /usr/sbin/sshd -D

If not, install it:

$ sudo apt-get install openssh-server

Also for your information:

  • My VirtualBox version: 5.2.6 r120293 (Qt5.6.2), 2018
  • My Ubuntu version: Ubuntu 16.04.3 LTS
  • My host machine: Windows 10
_失温 2024-11-12 20:44:59

SSH Back to Your Home / Office VirtualBox Guest Machine From The INTERNET

其他用户在这里提供的答案:如何通过主机从外部通过 SSH 连接到 VirtualBox 来宾?

...帮助我完成了从互联网上连接到我家用计算机的来宾计算机的任务。您应该能够使用计算机、平板电脑和智能手机(Android、iPhone 等)进行连接。我添加了更多步骤,以防对其他人有帮助:

这是我的设置的快速图表:

  • 远程设备 --->互联网 -->调制解调器 -->路由器-->主机 -->来宾虚拟机

  • 远程设备(ssh 客户端)--->直通设备 ---> GUEST VM(ssh 服务器)

  • 远程设备(保留 ssh 端口 3022)--->互联网 -->调制解调器 -->路由器(转发从:p3022 到:p3022)-->主机(转发从:p3022 到:p22) -->访客虚拟机(到达 ssh 端口 22)

对我来说,关键是要认识到所有连接都是从远程 PC 到家中的来宾虚拟机的直通中间设备 - -因此端口转发!

笔记:
* 需要 ssh 客户端来请求安全连接,并需要一个正在运行的 ssh 服务器来处理安全连接。

  • 我将转发上面所选答案中使用的端口 3022。

  • 在需要的地方输入您的 IP(家庭调制解调器/路由器、主机 IP、访客 IP 等),选择的名称只是示例 - 使用或更改。

1. 在调制解调器的 IP/路由器的外部 IP 地址上创建到端口 3022 的 ssh 隧道。

ssh 客户端/设备可能的命令:ssh -p 3022 user-name@home_external_IP

2.端口转发 = 我们通过从路由器到主机的连接

  • 同时确保防火墙/IPtable 规则打开路由器允许端口转发(如果需要打开)

  • 路由器的 Pfwd SCREEN 所需条目:AppName:SSH_Fwd、Port_from :3022,协议:both (UDP/TCP),IP_address:hostIP_address,Port_to:3022,其他一切都可以为空

DD-WRT 路由器软件资源 / Info:

3.主机防火墙:打开端口 3022 #so 转发的端口可以传递到来宾计算机

  • 主机:安装 VirtualBox、来宾添加项和来宾计算机(如果尚未完成)

  • 配置来宾计算机,然后按照下面的网络部分进行操作

  • 我使用 VirtualBox GUI 来设置来宾网络 - 比 CLI 更容易

  • 如果您想使用其他方法,请参阅:VirtualBox/manual/ch06.html#natforward

4.有些人建议使用网桥适配器来访问 LAN 和 LAN 上的其他计算机。这也会增加安全风险,因为现在您的来宾计算机现在暴露于 LAN 计算机,如果防火墙设置不正确,还可能暴露于 INTERNET 黑客。因此,我选择连接到 NAT 的网络适配器,以减少桥接安全风险。

在来宾计算机上执行以下操作:

  • 来宾计算机 VirtualBox 网络设置:适配器 1:连接到 NAT
  • 来宾计算机 VirtualBox 端口转发规则:名称:External_SSH、协议:TCP、主机端口:3022、来宾端口 22、主机和来宾 IP:离开空白
  • 点击网络部分中的高级然后点击端口转发输入规则
  • 访客机防火墙:打开端口22#so ssh连接可以进入
  • 访客机:确保ssh服务器已安装,配置正确,并运行
  • LINUX测试以查看是否ssh服务器运行 w/命令: sudo service ssh status
  • 可以检查 netstat 以查看是否已连接到来宾计算机上的端口 22

此外,根据使用的平台,还有不同的 ssh 服务器和客户端。

  • wikipedia/Secure_Shell
  • wikipedia/Comparison_of_SSH_servers
  • wikipedia/Comparison_of_SSH_clients

对于 Ubuntu 用户:

  • ubuntu 社区:SSHOpenSSH/Configuring
  • ubuntu/community: OpenSSH/Keys

应该就是这样了。如果我犯了错误或想添加任何内容 - 请随意这样做 - 我仍然是一个菜鸟。

希望这对某人有帮助。祝你好运!

SSH Back to Your Home / Office VirtualBox Guest Machine From The INTERNET

The answers provided by other users here : How to SSH to a VirtualBox guest externally through a host?

... helped me to accomplish the task of connecting from out on the internet to my home computer's guest machine. You should be able to connect using computers, tablets, and smart phones (android, IPhone,etc). I add a few more step in case it might be helpful to someone else:

Here is a quick diagram of my setup:

  • Remote device ---> INTERNET --> MODEM --> ROUTER --> HOST MACHINE --> GUEST VM

  • Remote device (ssh client) ---> PASS THRU DEVICES ---> GUEST VM (ssh server)

  • Remote device (leave ssh port 3022) ---> INTERNET --> MODEM --> ROUTER (FWD frm:p3022 to:p3022)--> HOST MACHINE (FWD frm:p3022 to:p22) --> GUEST VM (arrive ssh port 22)

The key for me was to realize that ALL connections was PASSING-THROUGH intermediary devices to get from my remote PC to my guest virtual-machine at home --Hence port forwarding!

Notes:
* Need ssh client to request a secure connection and a running ssh server to process the secure connection.

  • I will forward the port 3022 as used in the chosen answer from above.

  • Enter your IPs where needed (home modem/router, host IP, guest IP,etc.), Names chosen are just examples-use or change.

1.Create ssh tunnel to port 3022 on your modem's IP / router's external IP address.

ssh client/device possible commands: ssh -p 3022 user-name@home_external_IP

2.Port forward = we are passing thru the connection from router to host machine

  • Also make sure firewall /IPtable rules on router is allowing ports to be forward (open if needed)

  • Router's Pfwd SCREEN required entries: AppName:SSH_Fwd, Port_from: 3022, Protocol:both (UDP/TCP), IP_address:hostIP_address, Port_to:3022, everything else can be blank

DD-WRT router software resources / Info:

3.Host Machine Firewall: open port 3022 #so forwarded port can pass thru to guest machine

  • Host Machine: Install VirtualBox, guest additions, and guest machine if not done already

  • Configure guest machine and then follow the Network section below

  • I used VirtualBox GUI to setup guest's network- easier than CLI

  • If you want to use other methods refer to : VirtualBox/manual/ch06.html#natforward

4.Some suggest using Network Bridge adapter for guest = access to LAN and other machines on your LAN. This also pose an increase security risk, because now your guest machine is now exposed to LAN machines and possibly the INTERNET hackers if firewall not setup properly. So I selected Network adapter attached to NAT for less exposure to bridged security risks.

On the guest machine do the following:

  • Guest Machine VirtualBox Network settings: Adapter 1: Attached to NAT
  • Guest Machine VirtualBox Port Forwarding Rule: Name:External_SSH, Protocol:TCP, Host Port: 3022, Guest Port 22, Host&guest IPs:leave blank
  • click on advance in Network section then click on Port forwarding to enter rules
  • Guest Machine Firewall: open port 22 #so ssh connection can enter
  • Guest Machine: Make sure that ssh server is installed, configured properly, and running
  • LINUX test to see if ssh server running w/command: sudo service ssh status
  • Can check netstat to see if connection made to port 22 on the guest machine

Also there are different ssh servers and clients depending on platform using.

  • wikipedia/Secure_Shell
  • wikipedia/Comparison_of_SSH_servers
  • wikipedia/Comparison_of_SSH_clients

For Ubuntu Users:

  • ubuntu community: SSHOpenSSH/Configuring
  • ubuntu/community: OpenSSH/Keys

That should be it. If I made a mistake or want to add anything -feel free to do so-- I am still a noob.

Hope this helps someone. Good luck!

坚持沉默 2024-11-12 20:44:59

对于 Windows 主机,您可以:

  1. 在 vi​​rtualbox 管理器中:
    1. 在虚拟盒管理器中选择ctrl+G
    2. 然后进入网络面板
    3. 添加专用网络
      1. 确保未选择激活 DHCP
  2. 在网络管理(Windows)中 未选择激活 DHCP
    1. 选择新创建的 virtualbox 仅主机适配器和物理网卡
    2. 右键单击并选择“创建桥”
  3. 享受

For Windows host, you can :

  1. In virtualbox manager:
    1. select ctrl+G in your virtualbox manager,
    2. then go to network pannel
    3. add a private network
      1. make sure that activate DHCP is NOT selected
  2. In network management (windows)
    1. Select the newly created virtualbox host only adapter and the physical network card
    2. Right-Click and select "Make bridge"
  3. Enjoy
不顾 2024-11-12 20:44:59

您还可以从您的访客启动端口转发到您的主机或任何其他服务器。如果您的来宾被“锁定”或无法以其他方式完成ModifyVM 选项(例如没有VBoxManage 的权限),这尤其有用。

三个次要要求是 1) 您可以登录 VirtualBox Guest(通过“控制台”GUI、另一个 Guest 等),2) 您在 VirtualBox HOST(或其他服务器)上有一个帐户,以及 3) SSH 和 TCP转发不会被阻止。

假设您可以满足 3 个要求,步骤如下:

  1. 在来宾上,运行 netstat -rn 并找到默认路由目标 0.0.0.0 的网关地址。假设它是“10.0.2.2”。此“网关”地址是 VirtualBox 主机虚拟 IP(其中之一)。
  2. 在来宾上,运行 ssh -R 2222:localhost:22 10.0.2.2,其中“10.0.2.2”是 VirtualBox 服务器的 IP 地址 - 或者 - 您希望端口转发到的任何其他服务器 IP。
  3. 在主机上,运行 ssh 10.0.2.2 -p2222 ,其中 10.0.2.2 是步骤 1 中找到的默认网关/VBHost 虚拟 IP。如果它不是您要端口转发到的 VirtualBox 主机,则命令是 ssh localhost -p2222

You can also initiate a port forward TO your HOST, OR ANY OTHER SERVER, from your Guest. This is especially useful if your Guest is 'locked' or can't otherwise complete the ModifyVM option (e.g. no permission to VBoxManage).

Three minor requirements are 1) you are/can log into the VirtualBox Guest (via 'console' GUI, another Guest, etc), 2) you have an account on the VirtualBox HOST (or other Server), and 3) SSH and TCP forwarding is not blocked.

Presuming you can meet the 3 requirements, these are the steps:

  1. On the Guest, run netstat -rn and find the Gateway address to the default route destination 0.0.0.0. Let's say it's "10.0.2.2". This 'Gateway' address is (one of) the VirtualBox Host virtual IP(s).
  2. On the Guest, run ssh -R 2222:localhost:22 10.0.2.2 where "10.0.2.2" is the VirtualBox server's IP address -OR- any other server IP you wish to port forward to.
  3. On the Host, run ssh 10.0.2.2 -p2222 where 10.0.2.2 is the default gateway/VBHost virtual IP found in step 1. If it is NOT the VirtualBox host you are port forwarding to, then the command is ssh localhost -p2222
累赘 2024-11-12 20:44:59

按照以下步骤使用 putty 从主机登录到在 Virtual Box 中运行的 ubuntu 虚拟机(无需端口转发):

  1. 在 Virtualbox 管理器上选择虚拟机,单击设置图标。然后转到网络并启用两个适配器,如下所示:

    • 适配器 1(用于互联网访问):连接到 -> NAT,高级 ->检查连接的电缆。
    • 适配器 2:连接到 ->仅主机适配器,高级 ->检查电缆连接和混杂模式 ->允许全部。
  2. 启动 ubuntu 虚拟机。

  3. 以 root 身份登录虚拟机。
  4. 如下编辑文件“/etc/network/interfaces”并保存:

    自动定位
    iface lo inet环回
    
    自动 eth0
    iface eth0 inet dhcp
    
    自动 eth1
    iface eth1 inet dhcp
    
  5. 重新启动虚拟机。

  6. 登录虚拟机并运行以下命令来检查分配给 eth1 的 IP:

    <前><代码>ifconfig

  7. 使用此 IP 为虚拟机打开 putty 会话。

Follow below steps to login to your ubuntu VM running in virtual box from the host machine using putty (Without port forwarding):

  1. On Virtualbox manager select the vm, click on settings icon. Then go Networks and enable two adaptors as below:

    • Adaptor 1 (For internet access): Attached to -> NAT, Advanced -> Check the cable connected.
    • Adaptor 2: Attached to -> Host only adaptor, Advanced -> Check the cable connected and Promiscuous mode -> Allow all.
  2. Start the ubuntu vm.

  3. Login to the VM as root.
  4. Edit the file '/etc/network/interfaces' as below and save it:

    auto lo
    iface lo inet loopback
    
    auto eth0
    iface eth0 inet dhcp
    
    auto eth1
    iface eth1 inet dhcp
    
  5. Restart the VM.

  6. Login to the VM and run below command to check the IP allocated to eth1:

    ifconfig
    
  7. Use this IP to open putty session for the VM.

忆伤 2024-11-12 20:44:59

关于如何使用 NAT 配置端口转发的详细说明可以在 VirtualBox 文档中找到:
http://www.virtualbox.org/manual/ch06.html#natforward

A good explanation about how to configure port forwarding with NAT is found in the VirtualBox documents:
http://www.virtualbox.org/manual/ch06.html#natforward

短叹 2024-11-12 20:44:59

Ubuntu 18.04 LTS

配置桥接以查看服务器 IP,并在没有“端口转发”的情况下连接

VirtualBox >右键单击服务器>设置>网络>启用适配器 2 >选择“桥接”>混杂模式:允许所有>检查电缆连接>启动服务器

在ubuntu服务器上,编辑sudo nano /etc/netplan/*init.yaml文件,

我的示例文件:

network:
    ethernets:
        enp0s3:
            addresses: []
            dhcp4: true
        enp0s8:
            addresses: [192.168.0.200/24]
            dhcp4: no
            dhcp6: no
            nameservers:
               addresses: [8.8.8.8, 8.8.4.4]
    version: 2

对您有帮助的命令

nano /etc/netplan/file.yaml     # file to specify the rules of network
reboot now                      # restart ubuntu server right now
netplan apply                   # do after edited *.yaml, to apply changes
ifconfig -a                     # show interfaces with ip, netmask, broadcast, etc...
ping google.com                 # to see if there is internet

在 Ubuntu 上配置静态 IP 地址18.04 LTS 服务器 - 使用 NetPlan

Ubuntu 18.04 LTS

Configuration with bridged to see the server ip, and connect without "port forwarding"

VirtualBox > right click in server > settings > Network > enable adapter 2 > select "bridged" > Promiscuous mode: allow all > Check the cable connected > start server

On ubuntu server, edit sudo nano /etc/netplan/*init.yaml file,

My sample file:

network:
    ethernets:
        enp0s3:
            addresses: []
            dhcp4: true
        enp0s8:
            addresses: [192.168.0.200/24]
            dhcp4: no
            dhcp6: no
            nameservers:
               addresses: [8.8.8.8, 8.8.4.4]
    version: 2

Commands that will help you

nano /etc/netplan/file.yaml     # file to specify the rules of network
reboot now                      # restart ubuntu server right now
netplan apply                   # do after edited *.yaml, to apply changes
ifconfig -a                     # show interfaces with ip, netmask, broadcast, etc...
ping google.com                 # to see if there is internet

Configure Static IP Addresses On Ubuntu 18.04 LTS Server - with NetPlan

故事与诗 2024-11-12 20:44:59

只需将网络设置设置为桥接就可以了。

当您执行此操作时,您的 IP 将发生变化。然而,就我而言,它并没有立即改变。 ifconfig 返回相同的 IP。我重新启动了虚拟机,然后将 IP 设置为以 192.* 开头,并且立即允许我进行 ssh 访问。

Simply setting the Network Setting to bridged did the trick for me.

Your IP will change when you do this. However, in my case it didn't change immediately. ifconfig returned the same ip. I rebooted the vm and boom, the ip set itself to one start with 192.* and I was immediately allowed ssh access.

定格我的天空 2024-11-12 20:44:59

在安全网络上,将网络设置为桥接可能不起作用。管理员只能允许每个端口使用一个 MAC 地址,如果交换机在一个端口上检测到多个 MAC 地址,管理员甚至可以阻止该端口。

我认为最好的解决方案是设置额外的网络接口来处理您想要在计算机上运行的额外服务。因此,当我将笔记本电脑带回家时,我有一个桥接接口,可以进行桥接,并且可以从网络上的其他设备通过 SSH 进入它,并且当我想在连接时从我的笔记本电脑通过 SSH 进入我的虚拟机时,我有一个仅主机适配器连接到校园内的 eduroam wifi 网络。

On secure networks setting your network to bridge might not work. Administrators could only allow one mac address per port or even worse block the port should the switches detect multiple macs on one port.

The best solution in my opinion is to set up additional network interfaces to handle additional services you would like to run on your machines. So I have a bridge interface to allow for bridging when I take my laptop home and can SSH into it from other devices on my network as well as a host only adapter when I would like to SSH into my VM from my laptop when I am connected to the eduroam wifi network on campus.

宣告ˉ结束 2024-11-12 20:44:59

使用 NAT 网络适配器并添加端口转发。提及实际主机 IP。不要使用 127.0.0.1 或 localhost。

Use NAT network adapter and Add port forward. Mention actual host ip.Do not use 127.0.0.1 or localhost.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文