大网数据广告活动
服务器运维问答

Call the openvpn server by it's hostname

· 52CE 我爱测

I use an openvpn infrastructure with a server and some clients. The clients can call each other via their hostnames, but cannot reach the server in the same way. At the moment it is possible to reach the server via its IP address…

问题原文

原帖链接 · Santobert · CC BY-SA 4.0

I use an openvpn infrastructure with a server and some clients. The clients can call each other via their hostnames, but cannot reach the server in the same way. At the moment it is possible to reach the server via its IP address.

How can I transfer the server name and the corresponding IP addresses (v4 and v6) to the clients?

If possible, i don't want to set up an extra dns server

已采纳解答

原帖链接 · Nanzikambe · CC BY-SA 4.0

Edit re-read your question:

Ok without a DNS server you would add the server's IP to the client's /etc/hosts file:

172.31.0.1 dns.local

I would recommend the dns server option though, it's straight-forward:

Install bind or dnsmasq on the openvpn server and add the following to its config:

push "dhcp-option DOMAIN yourdomain.local"
push "dhcp-option DNS X.X.X.X"

Where X.X.X.X is the IP bind/dnsmasq listens on.

The options do the following:

  1. DNS X.X.X.X -- Set primary domain name server IPv4 address. Repeat this option to set secondary DNS server addresses.
  2. DOMAIN yourdomain.local -- sets Connection-specific DNS

If the DNS server is not in the same network as the VPN clients you may need to use:

push "redirect-private bypass-dns"

Which will create a separate route to the DNS server that skips the VPN.

If you're using Bind, then your named.conf would contain:

zone "local" IN {
    type master;
    allow-update { none; }; 
    notify no;
    file "/etc/bind/local.zone";
};

And local.zone:

$TTL 600
@       IN      SOA     dns.local. root.local. (
                        2018061001      ; serial
                        12h             ; refresh
                        1h              ; retry
                        2w              ; expire
                        1h              ; minimum
                        )
;
                NS      ns              ; Inet Address of name                         server
                MX      10 mail.local.  ; Primary Mail Exchanger
                MX      20 mail.local.  ; Secondary Mail Exchanger
localhost       IN      A       127.0.0.1
dns             IN      A       172.31.0.1
ns              IN      A       172.31.0.1
mail            IN      A       172.31.0.1
client100       IN      A       172.31.0.100
client101       IN      A       172.31.0.101

If you're new to Bind make absolutely sure it does not respond on any Internet facing IP.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-02-19)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。