700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > Centos7桥接设置网络并使用xrdp+tigervnc实现桌面远程访问

Centos7桥接设置网络并使用xrdp+tigervnc实现桌面远程访问

时间:2020-12-07 04:34:55

相关推荐

Centos7桥接设置网络并使用xrdp+tigervnc实现桌面远程访问

最近用到了虚拟机,之前虚拟机的网络配置使用的NAT配置好了,但是无论怎样设置都无法使用局域网内的其它主机访问虚拟机的服务。经过了一天的折腾,远程主机仍然连接不上虚拟机服务,后来找到原因,NAT连接模式下局域网内的其它主机通过无线网卡连接虚拟机的映射,但是虚拟机从有线网卡中传递信号返回故局域网内其它主机实现对宿主主机的虚拟机的访问使用NAT模式是不可行的,看到有些人写的NAT的配置中将虚拟机的网络适配器ip地址修改为与宿主机ip同频段的地址,这种方法虽然实现了宿主机对虚拟机的访问但是此时的虚拟机是ping不到互联网络的(因为此时虚拟机的ip是NAT模式下分发的子网ip地址,与宿主机的ip不在一个网络内,故不可以实现网络访问)。

折腾了一天的时间后断然改用桥接的方式实现局域网内主机对虚拟机的访问设置。桥接的模式就是使虚拟机和宿主机在同一ip网络内,即给虚拟机一个物理地址共享主机的无线网卡。

###使用桥接配置网络###

下面主要是桥接的设置步骤。

####步骤一####

首先在虚拟机配置中更改网络模式为 桥接

####步骤二####

查看虚拟网络编辑器:(注意我们在NAT模式时需要设置网络编辑器,而在桥接模式上我们不需要对它进行更改,并且要确保模式中只有一种本地模式)

####步骤三####

打开宿主机的网络配置,对Vmnet8(对应上图中的适配器名称)进行配置Ipv4,要保证ip地址与宿主机的ip在同一个ip频段上,但不要与宿主机ip相同,网关一定要与宿主机的网关一样,子网掩码也要与宿主机相同,一般子网掩码为255.255.255.0

####步骤四####

在Centos的虚拟机上设置网络,由于我是从NAT切换成桥接模式的所以我这是在NAT模式上进行的修改,BOOTPROTO=“static”静态获取ip (ip对应宿主机的ip频段但与宿主机ip地址不能一样,网关以及子网掩码与宿主机相同),当然可以设置成 BOOTPROTO=“dhcp”动态获取,并且将IPADDR及以下的设置删除掉。

另外ONBOOT要为yes。有些人的电脑中不存在ifcfg-ens33文件,使用命令cd /etc/sysconfig/network-scripts进入network-scripts文件夹内使用ls查看ifcfg-ensxxxx文件并进行如下设置。

执行命令 sudo vi /etc/sysconfig/network 点击i键进入修改模式后设置GATEWAY(网关)与主机网关相同,HOSTNAME随意设置。修改完成后Esc并使用:wq保存。

执行命令 sudo vi /etc/resolv.conf 进入后点击i键进行修改操作。内容如下:

其中nameserver与网关地址一致。修改完成后Esc并使用:wq保存。

至此所有设置完成,在终端执行ping 主机ip可以查看通讯。

###xrdp+tigervnc实现远程桌面设置###

####安装步骤####

首先安装xrdp:

执行命令:yun install epel-release这个软件包会自动配置yum的软件仓库。如果你也可以不安装这个包,自行配置软件仓库也是一样的

执行命令:yun install xrdp实现对xrdp的安装

执行命令:yum install tigervnc tigervnc-server实现tigervnc的安装(远程桌面的一种实现方式)

执行命令:chcon -t bin_t /usr/sbin/xrdp

执行命令:chcon -t bin_t /usr/sbin/xrdp-sesman实现对xrdp服务的设置

执行命令:systemctl start xrdp启动xrdp服务

执行命令:systemctl enable xrdp通过systemctl enable实现xrdp服务的开机自启的设置

执行命令:netstat -antup|grep xrdp查看xrdp与xrdp-sesman的启动情况

接下来就是为防火墙添加3389的访问接口( Server远程桌面的服务端口)

执行命令:firewall-cmd --permanent --zone=public --add-port=3389/tcp

执行命令:firewall-cmd --reload

至此实现远程桌面的设置,连接远程桌面时地址为 : 你的虚拟机的ip地址:3389 输入用户名和密码登录远程桌面。

####安装记录####

以下是安装记录打印可供参考:

[root@localhost superme]# yum install epel-release已加载插件:fastestmirror, langpacksLoading mirror speeds from cached hostfile* base: * extras: mirrors.* updates: 正在解决依赖关系There are unfinished transactions remaining. You might consider running yum-complete-transaction, or "yum-complete-transaction --cleanup-only" and "yum history redo last", first to finish them. If those don't work you'll have to try removing/installing packages by hand (maybe package-cleanup can help).--> 正在检查事务---> 软件包 epel-release.noarch.0.7-11 将被 安装--> 解决依赖关系完成依赖关系解决================================================================================Package架构 版本 源大小================================================================================正在安装:epel-release noarch 7-11 extras 15 k事务概要================================================================================安装 1 软件包总下载量:15 k安装大小:24 kIs this ok [y/d/N]: yDownloading packages:警告:/var/cache/yum/x86_64/7/extras/packages/epel-release-7-11.noarch.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEYepel-release-7-11.noarch.rpm 的公钥尚未安装epel-release-7-11.noarch.rpm | 15 kB 00:05从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 检索密钥导入 GPG key 0xF4A80EB5:用户ID: "CentOS-7 Key (CentOS 7 Official Signing Key) <security@>"指纹 : 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5软件包: centos-release-7-5.1804.el7.centos.x86_64 (@anaconda)来自 : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7是否继续?[y/N]:yRunning transaction checkRunning transaction testTransaction test succeededRunning transaction正在安装 : epel-release-7-11.noarch1/1 验证中: epel-release-7-11.noarch1/1 已安装:epel-release.noarch 0:7-11 完毕![root@localhost superme]# yum install xrdp已加载插件:fastestmirror, langpacksLoading mirror speeds from cached hostfileepel/x86_64/metalink | 4.9 kB00:00* base: * epel: ftp.yz.yamagata-u.ac.jp* extras: mirrors.* updates: epel | 5.4 kB00:00epel/x86_64/updateinfo FAILED http://ftp.riken.jp/Linux/fedora/epel/7/x86_64/repodata/f9261eaff5918473af07052ec939c36c94dba4243ba8aab79c58d4fde90d6ae7-updateinfo.xml.bz2: [Errno 14] HTTP Error 404 - Not Found正在尝试其它镜像。To address this issue please refer to the below wiki article /yum-errorsIf above article doesn't help to resolve this issue please use /.(1/3): epel/x86_64/group_gz | 90 kB 00:00epel/x86_64/updateinfo FAILED http://epel.dionipe.id/7/x86_64/repodata/f9261eaff5918473af07052ec939c36c94dba4243ba8aab79c58d4fde90d6ae7-updateinfo.xml.bz2: [Errno 14] HTTP Error 404 - Not Found正在尝试其它镜像。(2/3): epel/x86_64/updateinfo| 1.0 MB 00:02(3/3): epel/x86_64/primary_db| 6.7 MB 01:37正在解决依赖关系There are unfinished transactions remaining. You might consider running yum-complete-transaction, or "yum-complete-transaction --cleanup-only" and "yum history redo last", first to finish them. If those don't work you'll have to try removing/installing packages by hand (maybe package-cleanup can help).--> 正在检查事务---> 软件包 xrdp.x86_64.1.0.9.12-4.el7 将被 安装--> 解决依赖关系完成依赖关系解决================================================================================Package 架构 版本 源 大小================================================================================正在安装:xrdp x86_64 1:0.9.12-4.el7 epel 427 k事务概要================================================================================安装 1 软件包总下载量:427 k安装大小:2.1 MIs this ok [y/d/N]: yDownloading packages:警告:/var/cache/yum/x86_64/7/epel/packages/xrdp-0.9.12-4.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID 352c64e5: NOKEYxrdp-0.9.12-4.el7.x86_64.rpm 的公钥尚未安装xrdp-0.9.12-4.el7.x86_64.rpm | 427 kB 00:08从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 检索密钥导入 GPG key 0x352C64E5:用户ID: "Fedora EPEL (7) <epel@>"指纹 : 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5软件包: epel-release-7-11.noarch (@extras)来自 : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7是否继续?[y/N]:yRunning transaction checkRunning transaction testTransaction test succeededRunning transaction正在安装 : 1:xrdp-0.9.12-4.el7.x86_64 1/1 验证中: 1:xrdp-0.9.12-4.el7.x86_64 1/1 已安装:xrdp.x86_64 1:0.9.12-4.el7 完毕![root@localhost superme]# yum install tigervnc tigervnc-server已加载插件:fastestmirror, langpacksLoading mirror speeds from cached hostfile* base: * epel: ftp.riken.jp* extras: mirrors.* updates: 正在解决依赖关系There are unfinished transactions remaining. You might consider running yum-complete-transaction, or "yum-complete-transaction --cleanup-only" and "yum history redo last", first to finish them. If those don't work you'll have to try removing/installing packages by hand (maybe package-cleanup can help).--> 正在检查事务---> 软件包 tigervnc.x86_64.0.1.8.0-17.el7 将被 安装--> 正在处理依赖关系 tigervnc-icons,它被软件包 tigervnc-1.8.0-17.el7.x86_64 需要--> 正在处理依赖关系 libfltk_images.so.1.3()(64bit),它被软件包 tigervnc-1.8.0-17.el7.x86_64 需要--> 正在处理依赖关系 libfltk.so.1.3()(64bit),它被软件包 tigervnc-1.8.0-17.el7.x86_64 需要---> 软件包 tigervnc-server.x86_64.0.1.8.0-17.el7 将被 安装--> 正在检查事务---> 软件包 fltk.x86_64.0.1.3.4-1.el7 将被 安装---> 软件包 tigervnc-icons.noarch.0.1.8.0-17.el7 将被 安装--> 解决依赖关系完成依赖关系解决================================================================================Package 架构 版本 源 大小================================================================================正在安装:tigervncx86_64 1.8.0-17.el7 base 241 ktigervnc-server x86_64 1.8.0-17.el7 base 215 k为依赖而安装:fltkx86_64 1.3.4-1.el7base 560 ktigervnc-iconsnoarch 1.8.0-17.el7 base39 k事务概要================================================================================安装 2 软件包 (+2 依赖软件包)总下载量:1.0 M安装大小:2.6 MIs this ok [y/d/N]: yDownloading packages:(1/4): tigervnc-icons-1.8.0-17.el7.noarch.rpm | 39 kB 00:00(2/4): tigervnc-1.8.0-17.el7.x86_64.rpm| 241 kB 00:00(3/4): fltk-1.3.4-1.el7.x86_64.rpm| 560 kB 00:02(4/4): tigervnc-server-1.8.0-17.el7.x86_64.rpm | 215 kB 00:05--------------------------------------------------------------------------------总计 172 kB/s | 1.0 MB 00:06Running transaction checkRunning transaction testTransaction test succeededRunning transaction正在安装 : fltk-1.3.4-1.el7.x86_64 1/4 正在安装 : tigervnc-icons-1.8.0-17.el7.noarch2/4 正在安装 : tigervnc-1.8.0-17.el7.x86_64 3/4 正在安装 : tigervnc-server-1.8.0-17.el7.x86_644/4 验证中: tigervnc-server-1.8.0-17.el7.x86_641/4 验证中: tigervnc-icons-1.8.0-17.el7.noarch2/4 验证中: fltk-1.3.4-1.el7.x86_64 3/4 验证中: tigervnc-1.8.0-17.el7.x86_64 4/4 已安装:tigervnc.x86_64 0:1.8.0-17.el7tigervnc-server.x86_64 0:1.8.0-17.el7作为依赖被安装:fltk.x86_64 0:1.3.4-1.el7 tigervnc-icons.noarch 0:1.8.0-17.el7 完毕![root@localhost superme]# chcon -t bin_t /usr/sbin/xrdp[root@localhost superme]# chcon -t bin_t /usr/sbin/xrdp-sesman[root@localhost superme]# systemctl start xrdp[root@localhost superme]# systemctl enable xrdpCreated symlink from /etc/systemd/system/multi-user.target.wants/xrdp.service to /usr/lib/systemd/system/xrdp.service.[root@localhost superme]# systemctl status xrdp.service● xrdp.service - xrdp daemonLoaded: loaded (/usr/lib/systemd/system/xrdp.service; enabled; vendor preset: disabled)Active: active (running) since 六 -02-15 14:12:21 CST; 32s agoDocs: man:xrdp(8)man:xrdp.ini(5)Main PID: 4480 (xrdp)CGroup: /system.slice/xrdp.service└─4480 /usr/sbin/xrdp --nodaemon2月 15 14:12:21 localhost.localdomain systemd[1]: Started xrdp daemon.2月 15 14:12:21 localhost.localdomain systemd[1]: Starting xrdp daemon...2月 15 14:12:22 localhost.localdomain xrdp[4480]: (4480)(14054938884)[IN...2月 15 14:12:22 localhost.localdomain xrdp[4480]: (4480)(14054938884)[IN...2月 15 14:12:22 localhost.localdomain xrdp[4480]: (4480)(14054938884)[IN...2月 15 14:12:22 localhost.localdomain xrdp[4480]: (4480)(14054938884)[IN...Hint: Some lines were ellipsized, use -l to show in full.[root@localhost superme]# netstat -antup|grep xrdptcp 00 0.0.0.0:3389 0.0.0.0:*LISTEN4480/xrdp tcp 00 127.0.0.1:33500.0.0.0:*LISTEN4479/xrdp-sesman [root@localhost superme]# firewill -cmd --permanent --zone=public --add-port=3389/tcpbash: firewill: 未找到命令...[root@localhost superme]# firewall -cmd --permanent --zone=public --add-port=3389/tcpbash: firewall: 未找到命令...[root@localhost superme]# firewall-cmd --permanent --zone=public --add-port=3389/tcpsuccess[root@localhost superme]# firewall-cmd --reloadsuccess

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。