虽然微软改进了对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
(更新完)
2021-07-04更新
把Wifi共享给Ethernet的时候,在Sharing标签页的Home Networking Connection无法找到Ethernet。解决办法是把Sharing标签页的所有选项都去掉,然后选择应用,然后再重新勾选,就好了。
- Internet connection sharing Dropdown missing
- WINDOWS 10-INTERNET SHARING, NO SHARING TAB VISIBLE
- Internet Connection Sharing in Windows 10
(更新完)
2022-06-03更新
NoMachine
- nomachine只有Eterprise Desktop版支持Seamless模式,普通的免费版不支持。
- nomachine做服务端的话,需要创建一个额外的nx用户,而x2go则避免这个问题
VMWare
Hyper-V虚拟机访问外网的最佳方式还是通过VMWare的VMNet8虚拟网卡之上的NAT方式。
首先安装VMWare Station Player,对于个人使用是免费的,况且我们只是使用其VMNet8.
然后创建一个虚拟switch,以external的方式映射到VMNet8上。
发现从Windows 10升到11之后,原来那个虚拟switch就不能用了,要换个新的。
安装之后可能需要给虚拟机分配固定的IP和绑定一个NAT端口用于SSH,可以参考
- VMware Assign Static IP to Guest。
- how to give guest a static ip address
- vmware: unable to ping using NAT IP address, but can ping physical IP
简单说明一下:
-
在Hyper-V中为虚拟机设置固定的以太网MAC
-
在C:\ProgramData\VMWare\vmnetdhcp.conf中,为虚拟机指定一个固定的IP
host ArchLinux { hardware ethernet 00:11:22:33:44:55; fixed-address 192.168.91.100; }
-
在C:\ProgramData\VMWare\vmnetnat.conf中,为虚拟机指定一个端口绑定,用于SSH
示例:
8022 = 192.168.91.100:22
, -
重启VMWare的DHCP和NAT服务
VirtualBox
VirtualBox是type 2的虚拟机,跟操作系统的结合性比type 1的Hyper-V差一些。 另外其安装时附带的虚拟网卡是Host-only的。
VSCode
可以通过snap安装
sudo apt-get install snapd
sudo snap install code --classic
(更新完)
2022-09-01:在Ubuntu 22.04上安装fcitx5输入法
apt安装fcitx5:
sudo apt install fcitx5 fcitx5-chinese-addons
然后就可以使用fcitx5-configtool
来配置fcitx5,这条命令会提示运行fcitx5。
为了让GUI程序使用fcitx5作为输入法,须添加如下环境变量:
export XMODIFIERS=@im=fcitx5
export GTK_IM_MODULE=fcitx5
export QT_IM_MODULE=fcitx5
可以加到X的启动文件,或者shell的环境配置中, 比如zsh的~/.zshenv
。
可以从https://github.com/felixonmars/fcitx5-pinyin-zhwiki/releases下载词库,安装到~/.local/share/fcitx5/pinyin/dictionaries/
相关apt料包:
- 安装
fcitx5-material-color
可以增加主题数目 - 繁体的话,可以安装
fcitx5-chewing
fcitx5-diagnose
可以使用im-config
来将默认的输入法从auto
改为fcitx5
,(尝试了一下,未见生效)。
参考:
(更新完)