第一部分: 掛載 CentOS 8 Linux ISO 來當作本地倉庫,安裝套件。
步驟一:掛載 CentOS 8 ISO
3. 檢查防火牆設定
我有強烈可怕的健忘問題,這是幫助自己記憶的網站,記憶了許多個人的事. 收錄許多資訊,防止資料不見或網站消失,供查找留存用。 如:筆記,訊息,記錄,生活,網路小品,趣味之事.... 希望我不要連整個Blog也一起忘記.
介紹如何使用 dig 指令查詢各種 DNS 記錄,進行 DNS 審視與除錯。
dig若要在 CentOS Linux 中安裝 dig 指令,可以使用 yum 安裝 bind-utils 套件:
# 安裝 bind-utils 套件(CentOS)
sudo yum install bind-utils若在 Ubuntu Linux 中則可使用 apt 安裝 dnsutils 套件:
# 安裝 bind-utils 套件(Ubuntu)
sudo apt install dnsutils執行 dig 並指定完整的主機名稱,即可進行 DNS 正向查詢,靠系統預設的 DNS 伺服器取得對應的 IP 位址:
# 查詢 DNS 記錄
dig www.google.com; <<>> DiG 9.11.3-1ubuntu1.12-Ubuntu <<>> www.google.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 38378 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 65494 ;; QUESTION SECTION: ;www.google.com. IN A ;; ANSWER SECTION: www.google.com. 298 IN A 216.58.200.228 ;; Query time: 9 msec ;; SERVER: 127.0.0.53#53(127.0.0.53) ;; WHEN: Sun Jul 19 19:32:18 CST 2020 ;; MSG SIZE rcvd: 59
dig 預設的輸出非常詳細,這裡的輸出大致上可分為四的部份,第一個區塊顯示了本次 DNS 查詢的技術細節,包含查詢參數與傳回值等。QUESTION SECTION 部份顯示了送出的 DNS 查詢內容,預設的查詢類型為 IPv4 位址(A 記錄)。ANSWER SECTION 部份顯示了本次 DNS 查詢的結果。最後一部分則是一些附加資訊,例如 DNS 伺服器位址等。
若感覺 dig 的輸出過於冗長,可以加上 +short 參數改用簡略的輸出格式,這種輸出在撰寫指令稿時會比較好處理:
# 簡略輸出 dig www.google.com +short
216.58.200.228
另一種簡略的輸出方式是只輸出答案資訊部份:
# 只輸出答案資訊 dig www.google.com +noall +answer
; <<>> DiG 9.11.3-1ubuntu1.12-Ubuntu <<>> www.google.com +noall +answer ;; global options: +cmd www.google.com. 299 IN A 172.217.160.68
亦可關閉輸出註解,讓資訊更簡潔:
# 關閉輸出註解 dig +nocmd www.google.com +noall +answer
www.google.com. 299 IN A 172.217.160.68
若要進行 DNS 反向查詢,可以加上 -x 參數並指定要進行反查的 IP 位址:
# DNS 反向查詢 dig -x 172.217.160.68
; <<>> DiG 9.11.3-1ubuntu1.12-Ubuntu <<>> -x 172.217.160.68 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 17946 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 65494 ;; QUESTION SECTION: ;68.160.217.172.in-addr.arpa. IN PTR ;; ANSWER SECTION: 68.160.217.172.in-addr.arpa. 114 IN PTR tsa01s09-in-f4.1e100.net. ;; Query time: 0 msec ;; SERVER: 127.0.0.53#53(127.0.0.53) ;; WHEN: Sun Jul 19 20:30:55 CST 2020 ;; MSG SIZE rcvd: 94
若要自行指定要使用的 DNS 伺服器,可以使用 @ 加上 DNS 伺服器 IP 位址的方式來指定,例如若要使用 Google 的 8.8.8.8 DNS 伺服器,就可以這樣寫:
# 指定 DNS 伺服器 dig @8.8.8.8 www.google.com
; <<>> DiG 9.11.3-1ubuntu1.12-Ubuntu <<>> @8.8.8.8 www.google.com ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 50489 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 512 ;; QUESTION SECTION: ;www.google.com. IN A ;; ANSWER SECTION: www.google.com. 215 IN A 172.217.160.100 ;; Query time: 8 msec ;; SERVER: 8.8.8.8#53(8.8.8.8) ;; WHEN: Mon Jul 20 08:12:31 CST 2020 ;; MSG SIZE rcvd: 59
dig 預設會查詢主機的 IPv4 位址(A 記錄),若要查詢其他類型的 DNS 記錄,可在完整主機名稱後方加上欲查詢的 DNS 記錄類型,常見的 DNS 記錄類型有 A、AAAA、MX、TXT、NS、CNAME 與 SOA 等。
例如查詢 google.com 網域的郵件伺服器(MX 記錄):
# 查詢 MX 類型的 DNS 記錄
dig google.com MX; <<>> DiG 9.11.3-1ubuntu1.12-Ubuntu <<>> google.com MX ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 59995 ;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 65494 ;; QUESTION SECTION: ;google.com. IN MX ;; ANSWER SECTION: google.com. 409 IN MX 40 alt3.aspmx.l.google.com. google.com. 409 IN MX 50 alt4.aspmx.l.google.com. google.com. 409 IN MX 20 alt1.aspmx.l.google.com. google.com. 409 IN MX 30 alt2.aspmx.l.google.com. google.com. 409 IN MX 10 aspmx.l.google.com. ;; Query time: 0 msec ;; SERVER: 127.0.0.53#53(127.0.0.53) ;; WHEN: Sun Jul 19 20:20:36 CST 2020 ;; MSG SIZE rcvd: 147
若要查詢所有類型的 DNS 記錄,可將類型指定為 ANY:
# 查詢所有類型 DNS 記錄
dig www.google.com ANY; <<>> DiG 9.11.3-1ubuntu1.12-Ubuntu <<>> www.google.com ANY ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 5077 ;; flags: qr rd ra; QUERY: 1, ANSWER: 9, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 65494 ;; QUESTION SECTION: ;www.google.com. IN ANY ;; ANSWER SECTION: www.google.com. 199 IN A 64.233.189.99 www.google.com. 199 IN A 64.233.189.106 www.google.com. 199 IN A 64.233.189.147 www.google.com. 199 IN A 64.233.189.105 www.google.com. 199 IN A 64.233.189.103 www.google.com. 199 IN A 64.233.189.104 www.google.com. 199 IN AAAA 2404:6800:4008:c07::93 www.google.com. 199 IN AAAA 2404:6800:4008:c07::6a www.google.com. 199 IN AAAA 2404:6800:4008:c07::69 ;; Query time: 10 msec ;; SERVER: 127.0.0.53#53(127.0.0.53) ;; WHEN: Sun Jul 19 20:08:55 CST 2020 ;; MSG SIZE rcvd: 223
當 DNS 的解析出現問題時,可加上 +trace 參數讓 dig 從根節點追蹤查詢路徑,釐清問題的所在:
# 從根節點追蹤查詢路徑 dig www.google.com +trace
尋找問題時,通常也會配合不同的 DNS 伺服器交叉比對查詢結果:
# 指定 DNS 伺服器,從根節點追蹤查詢路徑 dig @8.8.8.8 www.google.com +trace
dig 設定檔使用者若有慣用的 dig 參數,可將參數設定寫在 ~/.digrc 這個設定檔中,這樣在執行 dig 的時候就會自動套用這些參數:
# 建立 dig 設定檔 echo "+noall +answer" > ~/.digrc
若要一次對大量的主機進行 DNS 記錄查詢,可以將所有的主機寫在一個文字檔案中,一行一個主機,再以 -f 參數指定輸入檔進行 DNS 查詢。
例如建立一個文字檔案 input.txt,內容如下:
google.com ubuntu.com tw.yahoo.com
然後進行大量批次 DNS 記錄查詢:
# 從檔案輸入進行批次查詢 dig -f input.txt
# dd if=/dev/hda of=hda.img 30544113+0 records in 30544113+0 records out # ls -lh -rw-r--r-- 1 root root 9.6G 2008-01-22 14:12 hda.img
# parted hda.img GNU Parted 1.7.1 Using /data/rabbit/disk_image/test2 Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) unit Unit? [compact]? B (parted) print Disk /data/rabbit/disk_image/test2: 10262568959B Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 32256B 106928639B 106896384B primary ext3 boot 2 106928640B 1184440319B 1077511680B primary linux-swap 3 1184440320B 10256924159B 9072483840B primary ext3 (parted) quit
#mount -o loop,ro,offset=32256 hda.img /mnt/rabbit
#umount /mnt/rabbit #mount -o loop,ro,offset=1184440320 test2 /mnt/rabbit #mount: wrong fs type, bad option, bad superblock on /dev/loop0, missing codepage or helper program, or other error In some cases useful info is found in syslog - try dmesg | tail or so
#dd if=hda.img of=hda3.img bs=512 skip=2313360 count=17719695 17719695+0 records in 17719695+0 records out 9072483840 bytes (9.1 GB) copied, 485.679 seconds, 18.7 MB/s
# mount -o loop hda3.img /mnt/rabbit/ # df -h /mnt/rabbit Filesystem Size Used Avail Use% Mounted on /data/rabbit/image/hda3.img 8.4G 6.3G 1.7G 80% /mnt/rabbit
cat, pv, or dd) and I need to access separate partitions. Unfortunately, the patch allowing partitions on loop devices to be accessed via their own device nodes does not appear to be in the latest (Debian) 2.6.18 kernels — the loop module does not have a max_part parameter, according to modinfo.msdos partition table type, I think I have found the solution, and the urge to document it for posterity.-o parameter to losetup, which specifies how many bytes into the disk a given partition starts. Getting this number isn't straight forward. Well, it is, if you know how, which is why I am writing this.$ /sbin/fdisk -lu disk.img
You must set cylinders.
You can do this from the extra functions menu.
Disk disk.img: 0 MB, 0 bytes
255 heads, 63 sectors/track, 0 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes
Device Boot Start End Blocks Id System
disk.imgp1 * 63 96389 48163+ 83 Linux
disk.imgp2 96390 2056319 979965 82 Linux swap / Solaris
disk.imgp3 2056320 78140159 38041920 5 Extended
disk.imgp5 2056383 3052349 497983+ 83 Linux
disk.imgp6 3052413 10859939 3903763+ 83 Linux
disk.imgp7 10860003 68372639 28756318+ 83 Linux
disk.imgp8 68372703 76180229 3903763+ 83 Linux
disk.imgp9 76180293 78140159 979933+ 83 Linux
fdisk complaining not being able to extract the number of cylinders, since it has to operate on a file which does not provide an ioctl interface.fdisk output. We know that each sector is 512 bytes, so:10860003 * 512 = 5560321536
losetup produces the desired result:# losetup /dev/loop0 disk.img -o $((10860003 * 512))
# file -s /dev/loop0
/dev/loop0: Linux rev 1.0 ext3 filesystem data
# mount /dev/loop0 /mnt
[...]
# umount /mnt
# losetup -d /dev/loop0
mount set up the loop device, and manage it automatically:# mount -o loop,offset=$((10860003 * 512)) disk.img /mnt
[...]
# umount /mnt
# plosetup lapse.hda .
I: partition 1 of lapse.hda will become ./lapse.hda_p1 (/dev/loop0)...
I: plosetup: skipping partition 2 of type 82...
I: plosetup: skipping partition 3 of type 5...
I: partition 5 of lapse.hda will become ./lapse.hda_p5 (/dev/loop1)...
I: partition 6 of lapse.hda will become ./lapse.hda_p6 (/dev/loop2)...
I: partition 7 of lapse.hda will become ./lapse.hda_p7 (/dev/loop3)...
I: partition 8 of lapse.hda will become ./lapse.hda_p8 (/dev/loop4)...
I: partition 9 of lapse.hda will become ./lapse.hda_p9 (/dev/loop5)...
# ls -l
total 0
lrwxrwxrwx 1 root root 10 2006-10-20 13:25 lapse.hda_p1 -> /dev/loop0
lrwxrwxrwx 1 root root 10 2006-10-20 13:25 lapse.hda_p5 -> /dev/loop1
lrwxrwxrwx 1 root root 10 2006-10-20 13:25 lapse.hda_p6 -> /dev/loop2
lrwxrwxrwx 1 root root 10 2006-10-20 13:25 lapse.hda_p7 -> /dev/loop3
lrwxrwxrwx 1 root root 10 2006-10-20 13:25 lapse.hda_p8 -> /dev/loop4
lrwxrwxrwx 1 root root 10 2006-10-20 13:25 lapse.hda_p9 -> /dev/loop5
# plosetup -c .
# ls -l
total 0
$((...)) style arithmetic. dash manages to overflow at 32bit. zsh and bash seem to get it right. If in doubt, use perl or a calculator.●本機指令 ● AD 指令 ● PowerShell 指令 --------------------------------------------------- 抓取使用者在 AD 相關設定 Gpresult /R 抓取電腦本機在 AD 相關設定 Gpres...