docker运行一个bind9和常用的网络命令
//
# docker运行一个bind9和常用的网络命令
提示: 启动用户所属主ID:101
# 拷贝初始配置文件
mkdir -p /data/bind9/bind && cd /data/bind9
docker run -d --name bind9-container -e TZ=UTC -p 30053:53 -p 30053:53/udp ubuntu/bind9:9.18-22.04_edge
#只保留这几个文件:bind.keys named.conf named.conf.default-zones named.conf.options rndc.key
docker cp bind9-container:/etc/bind bind_tmp
cd bind_tmp && cp bind.keys named.conf named.conf.default-zones named.conf.options rndc.key ../bind/
docker rm -f bind9-container
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# 修改配置文件
当前主机IP: 192.168.0.10
cd /data/bind9
cat >bind/named.conf.default-zones<<'EOF'
zone "." {
type hint;
file "/usr/share/dns/root.hints";
};
zone "yfklife.cn" IN {
type master;
file "/etc/bind/yfklife.cn";
};
EOF
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
cat >bind/yfklife.cn<<'EOF'
@ IN SOA yfklife.cn. root (
1 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
86400 ) ; Negative Cache TTL
;
IN NS ns1.yfklife.cn.
ns1 IN A 192.168.0.10
@ IN A 192.168.0.200
ci IN A 192.168.0.200
git IN A 192.168.0.201
loki IN A 192.168.0.202
EOF
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 配置docker-compose
cd /data/bind9
cat >docker-compose.yaml<<'EOF'
version: '3'
services:
bind9:
restart: always
network_mode: bridge
image: ubuntu/bind9:9.18-22.04_edge
container_name: bind9
environment:
- TZ=Asia/Shanghai
volumes:
- /etc/localtime:/etc/localtime
- ./bind:/etc/bind
ports:
- "53:53/tcp"
- "53:53/udp"
EOF
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
- 启动
文件授权:chown -R 101.101 /data/bind9/bind
docker-compose -f docker-compose.yaml up -d
# dig命令
- 安装
#centos
yum install bind-utils -y
#ubuntu
apt install dnsutils -y
1
2
3
4
5
2
3
4
5
dig @192.168.0.10 git.yfklife.cn
dig ANY +short @192.168.0.10 test-01.yfklife.cn
- 指定dns服务端口:55353
dig +short docker.com @192.168.0.10 -p 55353
- dns追踪,利用多个域名对比权威的dns解析商
dig +trace @192.168.0.10 baidu.com
# traceroute路由追踪
traceroute的工作原理是基于ICMP(Internet Control Message Protocol)和IP头部的TTL(Time To Live)字段
- 解析请求地址,直接显示IP地址
traceroute -n www.baidu.com
- 指定吓一跳次数3次
traceroute -m 3 www.baidu.com
- 指定端口:443
traceroute -p 443 www.baidu.com
# ip route
- 添加路由
优先选择metric值最小的路由
ip route add 192.168.10.0/24 via 192.168.10.1 dev ens21f1 metric 99
- 删除路由
ip route del 192.168.10.0/24 via 192.168.10.1 dev ens21f1 metric 99
# Ubuntu22.04 设置开机自启动
- 方式一
使用netplan 服务管理
- 方式二
cat >/etc/init.d/ip_route<<'EOF'
#!/bin/bash
### BEGIN INIT INFO
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
### END INIT INFO
case "$1" in
start) ip route add 10.61.16.0/24 via 192.168.108.1
;;
stop) ip route del 10.61.16.0/24 via 192.168.108.1
;;
status)
netstat -rn
;;
*)
echo "Usage: $0
{start|stop|status}"
exit 1
;;
esac
exit 0
EOF
chmod +x /etc/init.d/ip_route
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
update-rc.d ip_route defaults 99
systemctl enable ip_route
- 方式三
通过systemd 和脚本
#添加systemd单元
cat >/lib/systemd/system/ip_route.service<<'EOF'
[Unit]
Description=Add ip route
After=networkd-dispatcher.service
[Service]
Type=simple
ExecStart=/etc/init.d/ip_route.sh
[Install]
WantedBy=multi-user.target
EOF
#配置启动脚本
cat >/etc/init.d/ip_route.sh<<'EOF'
#!/bin/bash
ip route add 192.168.10.0/24 via 192.168.108.1 dev ens33 metric 99
systemctl enable ip_route
EOF
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//
如果此文章对您有帮助,点击 -->> 请博主喝咖啡 (opens new window)
上次更新: 2024/09/29, 18:31:32