73 lines
1.9 KiB
Markdown
73 lines
1.9 KiB
Markdown
#Using `sed` to modify a DNS zone
|
|
|
|
Take the following DNS zone as an example, say we needed to update the IP address from 110.232.142.185 to 45.65.88.152, you could modify the file using a text editor (see [editors](/commands#editors))
|
|
|
|
```bash
|
|
$TTL 86400
|
|
@ IN SOA ns1.benjamyn.love. servers.benjamyn.love. (
|
|
2018043009 ;Serial
|
|
3600 ;Refresh
|
|
1800 ;Retry
|
|
604800 ;Expire
|
|
43200 ;Minimum TTL
|
|
)
|
|
;Name Server Information
|
|
@ IN NS ns1.benjamyn.love.
|
|
@ IN NS ns2.benjamyn.love.
|
|
;IP address of Name Server
|
|
primary IN A 110.232.142.184
|
|
;A - Record HostName To Ip Address
|
|
memes.sh. IN A 110.232.142.185
|
|
www IN A 110.232.142.185
|
|
;CNAME record
|
|
ftp IN CNAME memes.sh.
|
|
```
|
|
|
|
In this case we can just use `sed -i s/110.232.142.185/45.65.88.152/g filename`
|
|
|
|
The file gets changed to
|
|
```bash
|
|
$TTL 86400
|
|
@ IN SOA ns1.benjamyn.love. servers.benjamyn.love. (
|
|
2018043009 ;Serial
|
|
3600 ;Refresh
|
|
1800 ;Retry
|
|
604800 ;Expire
|
|
43200 ;Minimum TTL
|
|
)
|
|
;Name Server Information
|
|
@ IN NS ns1.benjamyn.love.
|
|
@ IN NS ns2.benjamyn.love.
|
|
;IP address of Name Server
|
|
primary IN A 110.232.142.184
|
|
;A - Record HostName To Ip Address
|
|
memes.sh. IN A 45.65.88.152 <--
|
|
www IN A 45.65.88.152 <--
|
|
;CNAME record
|
|
ftp IN CNAME memes.sh.
|
|
```
|
|
|
|
You can also use sed to update things like the serial number using some regex (which will need to be incremented for the DNS zone to be properly synced out)
|
|
|
|
The command will look like `sed -i s/.*Serial/" 2019010308 ;Serial"/g filename` (The quotes are to escape the ; character) and when run against the DNS zone it will update will look like
|
|
|
|
```bash
|
|
$TTL 86400
|
|
@ IN SOA ns1.benjamyn.love. servers.benjamyn.love. (
|
|
2019010308 ;Serial <--
|
|
3600 ;Refresh
|
|
1800 ;Retry
|
|
604800 ;Expire
|
|
43200 ;Minimum TTL
|
|
)
|
|
;Name Server Information
|
|
@ IN NS ns1.benjamyn.love.
|
|
@ IN NS ns2.benjamyn.love.
|
|
;IP address of Name Server
|
|
primary IN A 110.232.142.184
|
|
;A - Record HostName To Ip Address
|
|
memes.sh. IN A 45.65.88.152
|
|
www IN A 45.65.88.152
|
|
;CNAME record
|
|
ftp IN CNAME memes.sh.
|
|
``` |