使用NX远程登录Hyper-V虚拟机中的Ubuntu
虽然微软改进了对xRDP的支持,使得Hyper-V虚拟机中运行的Ubuntu和宿主可以有比较好的交互性,可以使用Enhanced Session Mode功能。但是还是存在若干性能不够强,不能独立显示某个应用程序窗口等缺点。
当今而论,性能最好的远程桌面协议莫过于NX,也就是Nomachine所使用的协议。到NX3为止,NX的协议和实现都是开源的;然而到了NX4,Nomachine就将协议和产品变成专有的了。所以你有两个选择,使用Nomachine提供的专有产品,或者使用继承自NX3的开源产品。
使用Nomachine
Nomachine分为客户端和服务端,这两个是在一个软件包里面发行的。首先到从Nomachine下载页面下载Window的安装包,在宿主的Windows系统里面安装。然后到Ubuntu虚拟机中,下载debian/ubuntu格式的nomachina软件包。当前下载的到的文件是nomachine_6.4.6_1_amd64.deb
,然后执行下面的命令进行安装:
sudo dpkg -i nomachine_6.4.6_1_amd64.deb
# 或者
sudo apt install nomachine_6.4.6_1_amd64.deb
可以用
sudo dkpg --list | grep nomachine
查看nomachine是否正确安装。以后如果准备删除的话,可以使用命令sudo dkpg -r nomachine
Nomachine的服务端带有控制台界面,对于远程桌面来说,有很高的易用性和可配置性。但是免费版的Nomachine不带有Floating Window Mode功能(也就是把虚拟机中的图形程序模拟成一个本地的程序来运行),只有订阅版的Nomachin才支持Floating Window Mode,这对一些人来说会是一个缺点。
使用x2go
x2go是基于开源的NX3,并且它本身也是开源的。虽然功能没有Nomachine强大,但是支持Floating Window Mode和Published Applications。
如果你用过Mac上的虚拟机Parallels,就知道它带有一个Coherence View Mode,和上面提到的Published Applications类似。Published Applications可以显示一个菜单,上面是各种可运行的远程应用,如同Windows的开始菜单, 不过显示的是Ubuntu的应用。
首先在Ubuntu上安装x2go服务端:
$ sudo apt-get install software-properties-common
# 添加x2go的安装源
$ sudo add-apt-repository ppa:x2go/stable
# 添加后会自动fresh,如果没有的话,手动执行下面的命令
$ sudo apt-get update
# 安装x2go server相关的软件包
$ sudo apt-get install x2goserver x2goserver-xsession
然后,在x2go的网站上下载Windows客户端,在本地安装,然后就可以使用客户端去连接服务端,使用方法和Nomachine类似。
在配置x2go session的时候,可以选择使用Single Application (Floating Window Mode)还有Published Applications。
调整Ubuntu的运行级别
有了远程桌面之后,就不需要把Ubuntu运行在runlevel 5(桌面模式),只需要运行在runlevel 3(共享模式)就行了。
使用以下命令可以修改Ubuntu的运行模式:
sudo systemctl set-default runlevel3.target
上面的命令输出
Removed /etc/systemd/system/default.target
Created symlink /etc/systemd/system/default.target -> /lib/systemd/system/multi-user.target
参考: How to boot into runlevel 3 (as default) on Ubuntu Bionic(18.04)?
参考
nomachine
- Install NoMachine Remote Desktop Tool On Ubuntu 16.04 / 17.10 / 18.04
- nomachine完美解决远程Ubuntu桌面
- How do I start an application in floating window mode?
- NoMachine Enterprise Client - Installation and Configuration Guide
NX
x2go
- X2Go Server installation
- How to Set Up a Remote Desktop with X2Go on Ubuntu 18.04
- Published Applications
其他
- How to graphically interface with a headless server?
- How to Connect to a Ubuntu 18.04 Server via Remote Desktop Connection using xRDP
- RemoteApp / Seamless RDP Linux Server
2019-06-06更新
Ubuntu18.04采用netplan来管理网络,具体的配置文件在/etc/netplan/01-network-manager-all.yaml
。修改这个配置文件,让Ubuntu18.04使用静态IP地址:
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
dhcp6: no
addresses: [192.168.0.110/24]
gateway4: 192.168.0.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
参考:
- How To Configure IP Address In Ubuntu 18.04 LTS
- Configure Static IP Addresses On Ubuntu 18.04 LTS Server
- How to Configure Network Static IP Address in Ubuntu 18.04
如果想用NetworkManager来管理,则可以使用其命令行nmcli
,具体参考:
- Assigning static IP address using nmcli
- How to Configure and Manage Network Connections Using ‘nmcli’ Tool
(更新完)
2020-05-14 更新
如果Ubuntu装在另外一个机子上,没有无线网。可以将一台有无线网的Windows机子将网络分享给Ubuntu。
对于Wifi来说,桥接好像不能工作,参考Bridge from Wifi to Ethernet not working (Windows 10)和Bridged Client Mode Issues
推荐的方式是使用Internet Connection Sharing,也就是ICS,参考
- ICS From WiFi to LAN on Win 10 pc
- How to set up and manage a Network Bridge connection on Windows 10
- Bridge Network Connections in Windows 7/8/10
简单地说,就是在无线网卡上开启网络共享,指定共享的网卡是另外一个连接Ubuntu的网卡。然后连接Ubuntu的网卡就会自动被设置为192.168.137.1。Ubuntu可以使用DHCP自动从该网关动态获取IP地址。
Ubuntu的netplan需要将配置更改如下:
network:
version: 2
ethernets:
enp3s0:
dhcp4: yes
dhcp-identifier: mac
具体参考https://netplan.io/examples。执行sudo netplan apply之后重启即可生效。
使用ip a
可以查看网络端口信息。
在C:\Windows\System32\drivers\etc\host.ics
中可以查看分配给ICS各个主机的ip地址,以及对于的主机名。值得注意的是,对应的主机名都是FQDN(Fully Qualified Domain Name),比如ubuntu.mshome.net
。在Ubuntu上可以使用hostname –fqdn来查询。
注意,Ubunt的hostname不能为FQDN,否则可能不被Windows的ICS识别。也不能设成如
ubuntu.local
之类的
其他参考
- Create a bootable USB stick on Windows
- https://ubuntu.com/server/docs/network-configuration
- How to get Ubuntu Host to Register Hostname With DNS Server
- Linux Secure Dynamic DNS Update with Windows DNS
- How to make a machine accessible from the LAN using its hostname
- http://www.hexacorn.com/blog/2018/03/31/the-little-known-i-think-secret-of-hosts-ics/
- https://serverfault.com/questions/452268/hosts-file-ignored-how-to-troubleshoot
- https://gerardnico.com/network/name/fqdn
- https://linuxconfig.org/how-to-change-hostname-on-ubuntu-20-04-focal-fossa-linux
- https://linuxconfig.org/how-to-change-fqdn-domain-name-on-ubuntu-20-04-focal-fossa-linux
- https://serverfault.com/questions/269838/what-is-the-difference-between-a-hostname-and-a-fully-qualified-domain-name
- https://en.wikipedia.org/wiki/.local
(更新完)