Skip to content

Commit

Permalink
feat: dns bind addr
Browse files Browse the repository at this point in the history
  • Loading branch information
yinheli committed Nov 25, 2022
1 parent 2068499 commit 785fdcc
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions config/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# default 0.0.0.0
# bind: 0.0.0.0

# default 53
dns_port: 53

Expand Down
1 change: 1 addition & 0 deletions src/config/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ mod test {
})
.unwrap();

assert_eq!(config.bind, "0.0.0.0".to_string());
assert_eq!(config.dns_port, 53);
assert_eq!(config.network, "10.89.0.1/16".to_string());
}
Expand Down
2 changes: 2 additions & 0 deletions src/config/setting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use super::{dns_table::DnsTable, hosts::Hosts};
#[derive(Debug, Deserialize)]
#[serde(default)]
pub struct Setting {
pub bind: String,
pub dns_port: u32,
pub dns_upstream: Vec<String>,
pub network: String,
Expand All @@ -26,6 +27,7 @@ pub struct Setting {
impl Default for Setting {
fn default() -> Self {
Self {
bind: "0.0.0.0".to_string(),
dns_port: 53,
dns_upstream: vec![String::from("1.2.4.8"), String::from("8.8.8.8")],
network: String::from("10.89.0.1/16"),
Expand Down
5 changes: 3 additions & 2 deletions src/dns/dns_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ pub(crate) async fn build_dns_server(setting: ArcSetting) -> Result<ServerFuture

let mut server = ServerFuture::new(Handler { catalog });
log::info!("dns listen port: {}", setting.dns_port);
server.register_socket(UdpSocket::bind(format!("0.0.0.0:{}", setting.dns_port)).await?);
server
.register_socket(UdpSocket::bind(format!("{}:{}", setting.bind, setting.dns_port)).await?);
server.register_listener(
TcpListener::bind(format!("0.0.0.0:{}", setting.dns_port)).await?,
TcpListener::bind(format!("{}:{}", setting.bind, setting.dns_port)).await?,
Duration::from_secs(5),
);

Expand Down

0 comments on commit 785fdcc

Please sign in to comment.