我已经在运行
bind9
作为Ubuntu 20.04下的DNS服务器在我的家庭网络上,以便拥有我自己的特殊域名。
要将域中的多个不同子域名称映射到同一台电脑上的特定端口,您需要在电脑上安装代理服务器以及本地网络的DNS服务器。域名通过DNS协议映射到特定的IP地址,而不是映射到IP地址的特定端口。
在我的例子中,我有与Ubuntu 20.04相同的PC硬件,其中(1)Bind9用于我的DNS服务器,(2)Apache用于我的代理服务器。我可以使用两台不同的电脑,一台作为DNS服务器,将域名解析为IP地址,另一台提供各种服务,这些服务可以通过单个IP端口访问,使用代理服务器侦听端口,以调度到服务的连接,或通过指定所需服务的正确端口号直接访问服务。
例如
http://kitchen.home/
kitchen.home
使用端口80,默认HTTP协议端口。DNS服务器用于解析域名
厨房家
到IP地址。URL为
http://kitchen.home:8081/
厨房家
然后打开到该IP地址的TCP连接,但使用端口8081而不是标准HTTP端口80。
所以对于
映射到该IP地址处的8080端口
http://hall.home/
要在该IP地址映射到端口8081,您需要将解析域名的DNS服务器与驻留在端口80(标准HTTP端口)的代理服务器相结合。然后,代理服务器将请求重定向到基于子域名选择的PC上的其他端口,
hall
或
kitchen
,表示整个域说明符,
厨房家
hall.home
看见
https://stackoverflow.com/a/58122704/1466970
Apache web服务器也可以用作代理服务器,这就是我正在研究的内容。请参阅DigitalOcean的本教程,
How To Use Apache HTTP Server As Reverse-Proxy Using mod_proxy Extension
Setting up a basic web proxy in apache
.
我的环境
Ubuntu 20.04 PC是我使用Apache web server的Subversion服务器。我大部分时间都在楼下的Windows 10电脑上,在需要的时候用PuTTY连接到带有一个或多个终端窗口的Ubuntu电脑。我计划在Windows 10 PC上与Visual Studio合作,通过Apache web服务器访问Subversion,并将Ubuntu PC用作数据库服务器(MySQL)、web服务器(Apache with Php)和微服务(golang和node.js)。
我想在Ubuntu PC上安装一个DNS服务器,然后让我的Windows 10 PC在使用标准DNS服务器(如8.8.8.8和8.8.4.4版本的Google)的同时,为一个特殊的域名使用本地DNS服务器。
How to Configure BIND9 DNS Server on Ubuntu 20.04
Domain Name Service (DNS)
和
Everything You Need To Know About Ubuntu DNS Servers
-
安装
绑定9
使用
sudo apt install bind9
-
sudo ufw allow Bind9
-
/etc/bind/named.conf.options
-
修改文件
/etc/bind/named.conf.local
-
创建的副本
/etc/bind/db.local
home.x
-
修改新文件,
/etc/bind/db.home.x
我想在本地使用的域名是
如果我输入一个
http://www.home.x/
http://home.x/svn
为了通过Apache访问Subversion,我必须设置它。看见
enabling Subversion access via Apache web server and DAV on Ubuntu
如果你对此感兴趣。
更改和修改文件的详细信息
我添加了一个
forwarders
文件的节
为了将我的Ubuntu服务器未知的任何DNS请求转发到其他DNS服务器。我从Windows 10命令返回的DNS服务器列表中复制的IP地址
ipconfig /all
我在Windows 10 PC上运行的。更改的文件如下:
rick@rick-MS-7B98:~/Documents$ cat /etc/bind/named.conf.options
options {
directory "/var/cache/bind";
// If there is a firewall between you and nameservers you want
// to talk to, you may need to fix the firewall to allow multiple
// ports to talk. See http://www.kb.cert.org/vuls/id/800113
// If your ISP provided one or more IP addresses for stable
// nameservers, you probably want to use them as forwarders.
// Uncomment the following block, and insert the addresses replacing
// the all-0's placeholder.
// forwarders {
// 0.0.0.0;
// };
// following forwards are to Google DNS servers at 8.8.8.8 and 8.8.4.4
forwarders {
8.8.8.8;
8.8.4.4;
209.55.27.13;
};
//========================================================================
// If BIND logs error messages about the root key being expired,
// you will need to update your keys. See https://www.isc.org/bind-keys
//========================================================================
dnssec-validation auto;
listen-on-v6 { any; };
};
/etc/bind/named。配置选项
,然后运行检查实用程序,没有发现任何错误,然后重新启动
bind
sudo named-checkconf
sudo systemctl restart bind9
接下来,我添加了一个新的
zone
/etc/bind/named。配置本地
为我的新本地域名创建DNS条目
. 修改后的文件如下所示:
rick@rick-MS-7B98:~/Documents$ cat /etc/bind/named.conf.local
//
// Do any local configuration here
//
// Consider adding the 1918 zones here, if they are not used in your
// organization
//include "/etc/bind/zones.rfc1918";
zone "home.x" {
type master;
file "/etc/bind/db.home.x";
};
最后,我需要创建文件
/等/绑定/数据库。家x
在中指定
file
的指令
/等/绑定/数据库。地方的
通过使用命令
sudo cp /etc/bind/db.local /etc/bind/db.home.x
然后我修改了文件
为了指定解析的域名所需的规则
家x
www.home.x
到我的Ubuntu PC的IP地址。修改后的文件如下所示:
rick@rick-MS-7B98:~/Documents$ cat /etc/bind/db.home.x
;
; BIND data file for local loopback interface
;
$TTL 604800
@ IN SOA home.x. root.home.x. (
2 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns.home.x.
@ IN A 192.168.0.4
@ IN AAAA ::1
ns IN A 192.168.0.4
www IN A 192.168.0.4
在这一点上,我可以通过使用
nslookup
命令窗口中的命令。我先尝试了一下,没有指定Ubuntu PC的IP地址,然后是Ubuntu PC的IP地址
C:\Users\rickc>nslookup home.x
Server: dns.google
Address: 8.8.8.8
*** dns.google can't find home.x: Non-existent domain
C:\Users\rickc>nslookup home.x 192.168.0.4
Server: UnKnown
Address: 192.168.0.4
Name: home.x
Addresses: ::1
192.168.0.4
Control Panel > Network and Internet > Network Connections
)查看我的网络适配器列表,以修改我的WiFi适配器使用的DNS服务器地址。通过在适配器上单击鼠标右键以弹出浮动菜单,选择属性以打开属性对话框,然后选择Internet协议版本4,然后单击对话框上的属性按钮并修改DNS服务器地址,可以找到此设置。下面是对话框的屏幕截图。
修改DNS服务器地址后,我重试了
nslookup查找
不指定DNS服务器地址,命令将查找
:
C:\Users\rickc>nslookup home.x
Server: UnKnown
Address: 192.168.0.4
Name: home.x
Addresses: ::1
192.168.0.4
当我测试的URL
将显示我的Apache web服务器的测试页面。当我测试的URL
web浏览器显示了我的Subversion存储库的目录树。当我使用访问Subversion存储库时
http://home.x/svn/trunk/
在Ankh Subversion插件和Visual Studio 2017中,它可以正常工作。
这个设置的一个问题是,如果我的Ubuntu PC没有启动并运行,那么Windows 10 PC将不会有正常运行的DNS服务器,除非Ubuntu PC启动,或者DNS服务器地址设置回WiFi适配器上的原始设置。以前,它被设置为发现DNS服务器。也许我可以将其更改回指定的DNS服务器地址,我的Ubuntu PC的IP地址,我的Windows 10 PC将发现我的Ubuntu PC作为DNS服务器。