{"id":165891,"date":"2019-12-23T08:33:16","date_gmt":"2019-12-23T00:33:16","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=165891"},"modified":"2019-12-06T08:34:20","modified_gmt":"2019-12-06T00:34:20","slug":"linux-ip-commands","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-ip-commands.html","title":{"rendered":"\u5982\u4f55\u5728 Linux \u7ec8\u7aef\u9a8c\u8bc1\u57df\u540d\u6216\u8ba1\u7b97\u673a\u540d\u7684 IP \u5730\u5740"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u672c\u6559\u7a0b\u4ecb\u7ecd\u4e86\u5982\u4f55\u5728 Linux \u7ec8\u7aef\u9a8c\u8bc1\u57df\u540d\u6216\u8ba1\u7b97\u673a\u540d\u7684 IP \u5730\u5740\u3002\u672c\u6559\u7a0b\u5c06\u5141\u8bb8\u4f60\u4e00\u6b21\u68c0\u67e5\u591a\u4e2a\u57df\u3002\u4f60\u53ef\u80fd\u5df2\u7ecf\u4f7f\u7528\u8fc7\u8fd9\u4e9b\u547d\u4ee4\u6765\u9a8c\u8bc1\u4fe1\u606f\u3002\u4f46\u662f\uff0c\u6211\u4eec\u5c06\u6559\u4f60\u5982\u4f55\u6709\u6548\u4f7f\u7528\u8fd9\u4e9b\u547d\u4ee4\u5728 Linux \u7ec8\u7aef\u4e2d\u8bc6\u522b\u591a\u4e2a\u57df\u7684 IP \u5730\u5740\u4fe1\u606f\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b 5 \u4e2a\u547d\u4ee4\u6765\u5b8c\u6210\u6b64\u64cd\u4f5c\u3002<\/p>\n

    \n
  • dig\u00a0\u547d\u4ee4\uff1a\u5b83\u662f\u4e00\u4e2a\u7528\u4e8e\u67e5\u8be2 DNS \u540d\u79f0\u670d\u52a1\u5668\u7684\u7075\u6d3b\u547d\u4ee4\u884c\u5de5\u5177\u3002<\/li>\n
  • host\u00a0\u547d\u4ee4\uff1a\u5b83\u662f\u7528\u4e8e\u6267\u884c DNS \u67e5\u8be2\u7684\u7b80\u5355\u7a0b\u5e8f\u3002<\/li>\n
  • nslookup\u00a0\u547d\u4ee4\uff1a\u5b83\u7528\u4e8e\u67e5\u8be2\u4e92\u8054\u7f51\u57df\u540d\u670d\u52a1\u5668\u3002<\/li>\n
  • fping\u00a0\u547d\u4ee4\uff1a\u5b83\u7528\u4e8e\u5411\u7f51\u7edc\u4e3b\u673a\u53d1\u9001 ICMP ECHO_REQUEST \u6570\u636e\u5305\u3002<\/li>\n
  • ping\u00a0\u547d\u4ee4\uff1a\u5b83\u7528\u4e8e\u5411\u7f51\u7edc\u4e3b\u673a\u53d1\u9001 ICMP ECHO_REQUEST \u6570\u636e\u5305\u3002<\/li>\n<\/ul>\n

    \u4e3a\u4e86\u6d4b\u8bd5\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3a\u00a0domains-list.txt \u7684\u6587\u4ef6\uff0c\u5e76\u6dfb\u52a0\u4e86\u4ee5\u4e0b\u57df\u3002<\/p>\n

    # vi \/opt\/scripts\/domains-list.txt\r\n\r\n2daygeek.com\r\n\r\nmagesh.co.in\r\n\r\nlinuxtechnews.com<\/pre>\n
    \u65b9\u6cd5 1\uff1a\u5982\u4f55\u4f7f\u7528 dig \u547d\u4ee4\u67e5\u627e\u57df\u7684 IP \u5730\u5740<\/strong><\/div>\n

    dig \u547d\u4ee4\u4ee3\u8868 \u201c\u57df\u540d\u4fe1\u606f\u6293\u624bDomain Information Groper\u201d\uff0c\u5b83\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u4e14\u7075\u6d3b\u7684\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u7528\u4e8e\u67e5\u8be2 DNS \u540d\u79f0\u670d\u52a1\u5668\u3002<\/p>\n

    \u5b83\u6267\u884c DNS \u67e5\u8be2\uff0c\u5e76\u663e\u793a\u6765\u81ea\u67e5\u8be2\u7684\u540d\u79f0\u670d\u52a1\u5668\u7684\u8fd4\u56de\u4fe1\u606f\u3002\u5927\u591a\u6570 DNS \u7ba1\u7406\u5458\u4f7f\u7528\u00a0dig\u00a0\u547d\u4ee4\u6765\u89e3\u51b3 DNS \u95ee\u9898\uff0c\u56e0\u4e3a\u5b83\u7075\u6d3b\u3001\u6613\u7528\u4e14\u8f93\u51fa\u6e05\u6670\u3002<\/p>\n

    \u5b83\u8fd8\u6709\u6279\u5904\u7406\u6a21\u5f0f\uff0c\u53ef\u4ee5\u4ece\u6587\u4ef6\u8bfb\u53d6\u641c\u7d22\u8bf7\u6c42\u3002<\/p>\n

    # dig 2daygeek.com | awk '{print $1,$5}'\r\n\r\n2daygeek.com. 104.27.157.177\r\n2daygeek.com. 104.27.156.177<\/pre>\n

    \u4f7f\u7528\u4ee5\u4e0b bash \u811a\u672c\u67e5\u627e\u591a\u4e2a\u57df\u7684 IP \u5730\u5740\u3002<\/p>\n

    # vi \/opt\/scripts\/dig-command.sh\r\n#!\/bin\/bash\r\nfor server in `cat \/opt\/scripts\/domains-list.txt`\r\ndo echo $server \"-\"\r\ndig $server +short\r\ndone | paste -d \" \" - - -<\/pre>\n

    \u6dfb\u52a0\u4ee5\u4e0a\u5185\u5bb9\u5230\u811a\u672c\u540e\uff0c\u7ed9 dig-command.sh\u00a0\u6587\u4ef6\u8bbe\u7f6e\u53ef\u6267\u884c\u6743\u9650\u3002<\/p>\n

    # chmod +x \/opt\/scripts\/dig-command.sh<\/pre>\n

    \u6700\u540e\u8fd0\u884c bash \u811a\u672c\u83b7\u5f97\u8f93\u51fa\u3002<\/p>\n

    # sh \/opt\/scripts\/dig-command.sh\r\n2daygeek.com - 104.27.156.177 104.27.157.177\r\nmagesh.co.in - 104.18.35.52 104.18.34.52\r\nlinuxtechnews.com - 104.27.144.3 104.27.145.3<\/pre>\n

    \u5982\u679c\u8981\u5728\u4e00\u884c\u4e2d\u8fd0\u884c\u4e0a\u9762\u7684\u811a\u672c\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u811a\u672c\u3002<\/p>\n

    # for server in 2daygeek.com magesh.co.in linuxtechnews.com; do echo $server \"-\"; dig $server +short; done | paste -d \" \" - - -<\/pre>\n

    \u6216\u8005\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b Shell \u811a\u672c\u67e5\u627e\u591a\u4e2a\u57df\u7684 IP \u5730\u5740\u3002<\/p>\n

    # for server in 2daygeek.com magesh.co.in linuxtechnews.com; do dig $server | awk '{print $1,$5}'; done\r\n\r\n2daygeek.com. 104.27.157.177\r\n2daygeek.com. 104.27.156.177\r\nmagesh.co.in. 104.18.34.52\r\nmagesh.co.in. 104.18.35.52\r\nlinuxtechnews.com. 104.27.144.3\r\nlinuxtechnews.com. 104.27.145.3<\/pre>\n
    \u65b9\u6cd5 2\uff1a\u5982\u4f55\u4f7f\u7528 host \u547d\u4ee4\u67e5\u627e\u57df\u7684 IP \u5730\u5740<\/strong><\/div>\n

    host \u547d\u4ee4\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u547d\u4ee4\u884c\u7a0b\u5e8f\uff0c\u7528\u4e8e\u6267\u884c\u00a0DNS \u67e5\u8be2\u3002\u5b83\u901a\u5e38\u7528\u4e8e\u5c06\u540d\u79f0\u8f6c\u6362\u4e3a IP \u5730\u5740\uff0c\u53cd\u4e4b\u4ea6\u7136\u3002\u5982\u679c\u672a\u63d0\u4f9b\u4efb\u4f55\u53c2\u6570\u6216\u9009\u9879\uff0chost\u00a0\u5c06\u6253\u5370\u5b83\u7684\u547d\u4ee4\u884c\u53c2\u6570\u548c\u9009\u9879\u6458\u8981\u3002<\/p>\n

    \u4f60\u53ef\u4ee5\u5728 host \u547d\u4ee4\u4e2d\u6dfb\u52a0\u7279\u5b9a\u9009\u9879\u6216\u8bb0\u5f55\u7c7b\u578b\u6765\u67e5\u770b\u57df\u4e2d\u7684\u6240\u6709\u8bb0\u5f55\u7c7b\u578b\u3002<\/p>\n

    # host 2daygeek.com | grep \"has address\" | sed 's\/has address\/-\/g'\r\n2daygeek.com - 104.27.157.177\r\n2daygeek.com - 104.27.156.177<\/pre>\n

    \u4f7f\u7528\u4ee5\u4e0b bash \u811a\u672c\u67e5\u627e\u591a\u4e2a\u57df\u7684 IP \u5730\u5740\u3002<\/p>\n

    # vi \/opt\/scripts\/host-command.sh\r\nfor server in `cat \/opt\/scripts\/domains-list.txt`\r\ndo host $server | grep \"has address\" | sed 's\/has address\/-\/g'\r\ndone<\/pre>\n

    \u6dfb\u52a0\u4ee5\u4e0a\u5185\u5bb9\u5230\u811a\u672c\u540e\uff0c\u7ed9\u00a0host-command.sh\u00a0\u6587\u4ef6\u8bbe\u7f6e\u53ef\u6267\u884c\u6743\u9650\u3002<\/p>\n

    # chmod +x \/opt\/scripts\/host-command.sh<\/pre>\n

    \u6700\u540e\u8fd0\u884c bash \u811a\u672c\u83b7\u5f97\u8f93\u51fa\u3002<\/p>\n

    # sh \/opt\/scripts\/host-command.sh\r\n2daygeek.com - 104.27.156.177\r\n2daygeek.com - 104.27.157.177\r\nmagesh.co.in - 104.18.35.52\r\nmagesh.co.in - 104.18.34.52\r\nlinuxtechnews.com - 104.27.144.3\r\nlinuxtechnews.com - 104.27.145.3<\/pre>\n
    \u65b9\u6cd5 3\uff1a\u5982\u4f55\u4f7f\u7528 nslookup \u547d\u4ee4\u67e5\u627e\u57df\u7684 IP \u5730\u5740<\/strong><\/div>\n

    nslookup \u547d\u4ee4\u662f\u7528\u4e8e\u67e5\u8be2\u4e92\u8054\u7f51\u57df\u540d\u670d\u52a1\u5668\uff08DNS\uff09\u7684\u7a0b\u5e8f\u3002<\/p>\n

    nslookup\u00a0\u6709\u4e24\u79cd\u6a21\u5f0f\uff0c\u5206\u522b\u662f\u4ea4\u4e92\u5f0f\u548c\u975e\u4ea4\u4e92\u5f0f\u3002\u4ea4\u4e92\u6a21\u5f0f\u5141\u8bb8\u7528\u6237\u67e5\u8be2\u540d\u79f0\u670d\u52a1\u5668\u4ee5\u83b7\u53d6\u6709\u5173\u5404\u79cd\u4e3b\u673a\u548c\u57df\u7684\u4fe1\u606f\uff0c\u6216\u6253\u5370\u57df\u4e2d\u7684\u4e3b\u673a\u5217\u8868\u3002\u975e\u4ea4\u4e92\u6a21\u5f0f\u7528\u4e8e\u4ec5\u6253\u5370\u4e3b\u673a\u6216\u57df\u7684\u540d\u79f0\u548c\u8bf7\u6c42\u7684\u4fe1\u606f\u3002<\/p>\n

    \u5b83\u662f\u4e00\u4e2a\u7f51\u7edc\u7ba1\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u5e2e\u52a9\u8bca\u65ad\u548c\u89e3\u51b3 DNS \u76f8\u5173\u95ee\u9898\u3002<\/p>\n

    # nslookup -q=A 2daygeek.com | tail -n+4 | sed -e '\/^$\/d' -e 's\/Address:\/\/g' | grep -v 'Name|answer' | xargs -n1\r\n104.27.157.177\r\n104.27.156.177<\/pre>\n

    \u4f7f\u7528\u4ee5\u4e0b bash \u811a\u672c\u67e5\u627e\u591a\u4e2a\u57df\u7684 IP \u5730\u5740\u3002<\/p>\n

    # vi \/opt\/scripts\/nslookup-command.sh\r\n#!\/bin\/bash\r\nfor server in `cat \/opt\/scripts\/domains-list.txt`\r\ndo echo $server \"-\"\r\nnslookup -q=A $server | tail -n+4 | sed -e '\/^$\/d' -e 's\/Address:\/\/g' | grep -v 'Name|answer' | xargs -n1 done | paste -d \" \" - - -<\/pre>\n

    \u6dfb\u52a0\u4ee5\u4e0a\u5185\u5bb9\u5230\u811a\u672c\u540e\uff0c\u7ed9\u00a0nslookup-command.sh\u00a0\u6587\u4ef6\u8bbe\u7f6e\u53ef\u6267\u884c\u6743\u9650\u3002<\/p>\n

    # chmod +x \/opt\/scripts\/nslookup-command.sh<\/pre>\n

    \u6700\u540e\u8fd0\u884c bash \u811a\u672c\u83b7\u5f97\u8f93\u51fa\u3002<\/p>\n

    # sh \/opt\/scripts\/nslookup-command.sh\r\n2daygeek.com - 104.27.156.177 104.27.157.177\r\nmagesh.co.in - 104.18.35.52 104.18.34.52\r\nlinuxtechnews.com - 104.27.144.3 104.27.145.3<\/pre>\n
    \u65b9\u6cd5 4\uff1a\u5982\u4f55\u4f7f\u7528 fping \u547d\u4ee4\u67e5\u627e\u57df\u7684 IP \u5730\u5740<\/strong><\/div>\n

    fping \u547d\u4ee4\u662f\u7c7b\u4f3c\u00a0ping\u00a0\u4e4b\u7c7b\u7684\u7a0b\u5e8f\uff0c\u5b83\u4f7f\u7528\u4e92\u8054\u7f51\u63a7\u5236\u6d88\u606f\u534f\u8bae\uff08ICMP\uff09echo \u8bf7\u6c42\u6765\u786e\u5b9a\u76ee\u6807\u4e3b\u673a\u662f\u5426\u54cd\u5e94\u3002
    \nfping\u00a0\u4e0e\u00a0ping\u00a0\u4e0d\u540c\uff0c\u56e0\u4e3a\u5b83\u5141\u8bb8\u7528\u6237\u5e76\u884c ping \u4efb\u610f\u6570\u91cf\u7684\u4e3b\u673a\u3002\u53e6\u5916\uff0c\u5b83\u53ef\u4ee5\u4ece\u6587\u672c\u6587\u4ef6\u8f93\u5165\u4e3b\u673a\u3002
    \nfping\u00a0\u53d1\u9001 ICMP echo \u8bf7\u6c42\uff0c\u5e76\u4ee5\u5faa\u73af\u65b9\u5f0f\u79fb\u5230\u4e0b\u4e00\u4e2a\u76ee\u6807\uff0c\u5e76\u4e14\u4e0d\u7b49\u5230\u76ee\u6807\u4e3b\u673a\u505a\u51fa\u54cd\u5e94\u3002
    \n\u5982\u679c\u76ee\u6807\u4e3b\u673a\u7b54\u590d\uff0c\u90a3\u4e48\u5c06\u5176\u6807\u8bb0\u4e3a\u6d3b\u52a8\u4e3b\u673a\u5e76\u4ece\u8981\u68c0\u67e5\u7684\u76ee\u6807\u5217\u8868\u4e2d\u5220\u9664\uff1b\u5982\u679c\u76ee\u6807\u5728\u7279\u5b9a\u65f6\u95f4\u9650\u5236\u548c\/\u6216\u91cd\u8bd5\u9650\u5236\u5185\u672a\u54cd\u5e94\uff0c\u90a3\u4e48\u5c06\u5176\u6307\u5b9a\u4e3a\u4e0d\u53ef\u8bbf\u95ee\u3002<\/p>\n

    # fping -A -d 2daygeek.com magesh.co.in linuxtechnews.com\r\n104.27.157.177 (104.27.157.177) is alive\r\n104.18.35.52 (104.18.35.52) is alive\r\n104.27.144.3 (104.27.144.3) is alive<\/pre>\n
    \u65b9\u6cd5 5\uff1a\u5982\u4f55\u4f7f\u7528 ping \u547d\u4ee4\u67e5\u627e\u57df\u7684 IP \u5730\u5740<\/strong><\/div>\n

    ping \u547d\u4ee4\uff08\u6570\u636e\u5305\u4e92\u8054\u7f51\u6293\u624bPacket Internet Groper\uff09\u662f\u4e00\u4e2a\u7f51\u7edc\u7a0b\u5e8f\uff0c\u7528\u4e8e\u6d4b\u8bd5 Internet \u534f\u8bae\uff08IP\uff09\u7f51\u7edc\u4e0a\u4e3b\u673a\u7684\u53ef\u7528\u6027\/\u8fde\u63a5\u6027\u3002<\/p>\n

    \u901a\u8fc7\u5411\u76ee\u6807\u4e3b\u673a\u53d1\u9001\u4e92\u8054\u7f51\u63a7\u5236\u6d88\u606f\u534f\u8bae\uff08ICMP\uff09Echo \u8bf7\u6c42\u6570\u636e\u5305\u5e76\u7b49\u5f85 ICMP Echo \u5e94\u7b54\u6765\u9a8c\u8bc1\u4e3b\u673a\u7684\u53ef\u7528\u6027\u3002<\/p>\n

    \u5b83\u57fa\u4e8e\u53d1\u9001\u7684\u6570\u636e\u5305\u3001\u63a5\u6536\u7684\u6570\u636e\u5305\u3001\u4e22\u5931\u7684\u6570\u636e\u5305\uff0c\u901a\u5e38\u5305\u542b\u6700\u5c0f\/\u5e73\u5747\/\u6700\u5927\u65f6\u95f4\u6765\u6c47\u603b\u7edf\u8ba1\u7ed3\u679c\u3002<\/p>\n

    # ping -c 2 2daygeek.com | head -2 | tail -1 | awk '{print $5}' | sed 's\/[(:)]\/\/g'\r\n104.27.157.177<\/pre>\n

    \u4f7f\u7528\u4ee5\u4e0b bash \u811a\u672c\u67e5\u627e\u591a\u4e2a\u57df\u7684 IP \u5730\u5740\u3002<\/p>\n

    # vi \/opt\/scripts\/ping-command.sh\r\n#!\/bin\/bash\r\nfor server in `cat \/opt\/scripts\/domains-list.txt`\r\ndo echo $server \"-\"\r\nping -c 2 $server | head -2 | tail -1 | awk '{print $5}' | sed 's\/[(:)]\/\/g'\r\ndone | paste -d \" \" - -<\/pre>\n

    \u6dfb\u52a0\u4ee5\u4e0a\u5185\u5bb9\u5230\u811a\u672c\u540e\uff0c\u7ed9 ping-command.sh\u00a0\u6587\u4ef6\u8bbe\u7f6e\u53ef\u6267\u884c\u6743\u9650\u3002<\/p>\n

    # chmod +x \/opt\/scripts\/ping-command.sh<\/pre>\n

    \u6700\u540e\u8fd0\u884c bash \u811a\u672c\u83b7\u5f97\u8f93\u51fa\u3002<\/p>\n

    # sh \/opt\/scripts\/ping-command.sh\r\n2daygeek.com - 104.27.156.177\r\nmagesh.co.in - 104.18.35.52\r\nlinuxtechnews.com - 104.27.144.3<\/pre>\n
    \n

    via:\u00a0https:\/\/www.2daygeek.com\/linux-command-find-check-domain-ip-address\/<\/a><\/p>\n

    \u4f5c\u8005\uff1aMagesh Maruthamuthu<\/a>\u00a0\u9009\u9898\uff1alujun9972<\/a>\u00a0\u8bd1\u8005\uff1ageekpi<\/a>\u00a0\u6821\u5bf9\uff1awxy<\/a><\/p>\n

    \u672c\u6587\u7531\u00a0LCTT<\/a>\u00a0\u539f\u521b\u7f16\u8bd1\uff0cLinux\u4e2d\u56fd<\/a>\u00a0\u8363\u8a89\u63a8\u51fa<\/p>\n","protected":false},"excerpt":{"rendered":"

    \u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b 5 \u4e2a\u547d\u4ee4\u6765\u5b8c\u6210\u6b64\u64cd\u4f5c\u3002 dig\u00a0\u547d\u4ee4\uff1a\u5b83\u662f\u4e00\u4e2a\u7528\u4e8e\u67e5\u8be2 DNS \u540d\u79f0\u670d\u52a1\u5668\u7684\u7075\u6d3b\u547d\u4ee4\u884c\u5de5\u5177\u3002 […]<\/p>\n","protected":false},"author":323,"featured_media":118928,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-165891","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/165891","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/323"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=165891"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/165891\/revisions"}],"predecessor-version":[{"id":166051,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/165891\/revisions\/166051"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/118928"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=165891"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=165891"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=165891"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}