不灭的焱

革命尚未成功,同志仍须努力下载JDK17

作者:Albert.Wen  添加时间:2018-06-28 11:21:41  修改时间:2024-04-30 14:23:11  分类:电脑/软件使用  编辑

电脑环境

宿主主机:Windows 7

虚拟系统:CentOS 6.8

配置NAT端口转发规则

第一步:配置 CentOS 网络开机自动启动

(1) 查看一下网卡:

[root@CentOS-A ~]# ifconfig 
eth0      Link encap:Ethernet  HWaddr 08:00:27:B1:C0:C8  
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:feb1:c0c8/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:270 errors:0 dropped:0 overruns:0 frame:0
          TX packets:158 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:30473 (29.7 KiB)  TX bytes:28348 (27.6 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

(2) 修改的网卡配置,设置 ONBOOT=yes,表示 该网卡开机自启动

[root@CentOS-A ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=08:00:27:B1:C0:C8
TYPE=Ethernet
UUID=a8c40313-69ed-4076-a05f-b3e7273b4ced
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp

第二步:配置 VirtualBox 虚拟主机网络的“端口转发规则”

案例:访问 Windows 7 里的 Nginx 80 端口,被转发到监听本机 8080 端口 的VirtualBox,然后 VirtualBox 又把它(8080端口)转发到  虚拟系统CentOS 中监听 80 端口 的 Nginx

{
	listen 80;
	server_name		www.php-note.com;
	access_log		logs/www.php-note.com_access.log;

	location / {
		proxy_redirect off;
		proxy_set_header Host $host;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_pass http://127.0.0.1:8080;
	}
}

第三步:重启 CentOS

init 6

第四步:用SSH连接CentOS

  • IP:127.0.0.1
  • 端口:2222         // 温馨提示:Windows 7 下,可用配置 本地的 22 端口,转发到 CentOS 的 22 端口,但是在 Mac 系统中,本地端口必须大于等于 1024
  • 用户:root
  • 密码:123456     // 自己设置的 CentOS root 密码

 

另外,还需做的事情:

1、Windows7 中,需要配置域名的 host 文件:C:\Windows\System32\drivers\etc\hosts

2、CentOS 中,需要:

(1) 配置域名的 host 文件:/etc/hosts

(2) 配置 nginx 域名主机头,即配置网站server节点

(3) 设置防火墙 80端口对外开放

 

 

参考:为VirtualBox配置端口映射