{"id":18188,"date":"2014-02-12T05:07:17","date_gmt":"2014-02-11T21:07:17","guid":{"rendered":"https:\/\/2blog.ilc.edu.tw\/25793\/2014\/02\/12\/%e7%94%b1-dhcp-server-%e7%9a%84%e5%8b%95%e6%85%8b-ip-%e8%bd%89%e6%88%90%e5%9b%ba%e5%ae%9a-ip-linux-server-%e7%af%87\/"},"modified":"2021-03-18T17:23:50","modified_gmt":"2021-03-18T09:23:50","slug":"%e7%94%b1-dhcp-server-%e7%9a%84%e5%8b%95%e6%85%8b-ip-%e8%bd%89%e6%88%90%e5%9b%ba%e5%ae%9a-ip-linux-server-%e7%af%87","status":"publish","type":"post","link":"https:\/\/2blog.ilc.edu.tw\/25793\/2014\/02\/12\/%e7%94%b1-dhcp-server-%e7%9a%84%e5%8b%95%e6%85%8b-ip-%e8%bd%89%e6%88%90%e5%9b%ba%e5%ae%9a-ip-linux-server-%e7%af%87\/","title":{"rendered":"\u7531 DHCP Server \u7684\u52d5\u614b IP \u8f49\u6210\u56fa\u5b9a IP &#8211; Linux Server \u7bc7"},"content":{"rendered":"<p>Linux\u00a0\u5b89\u88dd\u5b8c\u6210\u4e4b\u5f8c\uff0c\u5982\u679c\u6c92\u6709\u5728\u624b\u52d5\u6216\u81ea\u52d5\u5b89\u88dd\u4e2d\u8a2d\u5b9a\u597d\u7db2\u8def\u7d44\u614b\uff0c\u901a\u5e38\u5c31\u8981\u624b\u52d5\u8a2d\u5b9a\u7db2\u8def\uff0c\u4f46\u5982\u679c\u662f\u7528\u7531 DHCP Server\u00a0\u81ea\u52d5\u53d6\u5f97 IP\uff0c\u6703\u7bc0\u7701\u8a31\u591a\u7684\u6642\u9593\uff0c\u4f46\u5982\u679c\u662f Server\u00a0\u7684\u8a71\uff0c\u9084\u662f\u4f7f\u7528\u56fa\u5b9a IP\u00a0\u6703\u6bd4\u8f03\u597d\u3002[@more@]<br \/>\u5e95\u4e0b\u6587\u7ae0\u5167\u5bb9\u53d6\u81ea\uff1a<a href=\"http:\/\/wiki.centos.org\/HowTos\/NetworkInstallServer\" target=\"_blank\" rel=\"noopener noreferrer\">HowTos\/NetworkInstallServer &#8211; CentOS Wiki<\/a><br \/>1.\u00a0\u5efa\u7acb Script\u00a0\u6a94<br \/># <span style=\"color: #ff0000\">vim \/usr\/local\/bin\/set_static_ip<\/span><br \/><span style=\"color: #0000ff\">#!\/bin\/bash<\/span><br \/><span style=\"color: #0000ff\">echo &#8220;Converting DHCP scope to static IP address&#8221;<\/span><\/p>\n<p><span style=\"color: #0000ff\">DEVICE=`route -n|grep &#8216;^0.0.0.0&#8217;|awk &#8216;{print $8}&#8217;`<\/span><br \/><span style=\"color: #0000ff\">IPADDR=`ifconfig $DEVICE|grep &#8216;inet addr:&#8217;|awk &#8216;{sub(\/addr:\/,&#8221;&#8221;); print $2}&#8217;`<\/span><br \/><span style=\"color: #0000ff\">NETMASK=`ifconfig $DEVICE|grep &#8216;Mask&#8217;|awk &#8216;{sub(\/Mask:\/,&#8221;&#8221;); print $4}&#8217;`<\/span><br \/><span style=\"color: #0000ff\">NETWORK=`ipcalc $IPADDR -n $NETMASK|awk -F= &#8216;{print $2}&#8217;`<\/span><br \/><span style=\"color: #0000ff\">GATEWAY=`route -n|grep &#8216;^0.0.0.0&#8217;|awk &#8216;{print $2}&#8217;`<\/span><br \/><span style=\"color: #0000ff\">HWADDR=`ifconfig $DEVICE|grep &#8216;HWaddr&#8217;|awk &#8216;{print $5}&#8217;`<\/span><br \/><span style=\"color: #0000ff\">HOSTNAME=`hostname`<\/span><\/p>\n<p><span style=\"color: #0000ff\">cat &lt;&lt;EOF &gt;\/etc\/sysconfig\/network<\/span><br \/><span style=\"color: #0000ff\">NETWORKING=yes<\/span><br \/><span style=\"color: #0000ff\">HOSTNAME=$HOSTNAME<\/span><br \/><span style=\"color: #0000ff\">GATEWAY=$GATEWAY<\/span><br \/><span style=\"color: #0000ff\">EOF<\/span><\/p>\n<p><span style=\"color: #0000ff\">cat &lt;&lt;EOF &gt;\/etc\/sysconfig\/network-scripts\/ifcfg-$DEVICE<\/span><br \/><span style=\"color: #0000ff\">DEVICE=$DEVICE<\/span><br \/><span style=\"color: #0000ff\">BOOTPROTO=static<\/span><br \/><span style=\"color: #0000ff\">IPADDR=$IPADDR<\/span><br \/><span style=\"color: #0000ff\">NETMASK=$NETMASK<\/span><br \/><span style=\"color: #0000ff\">ONBOOT=yes<\/span><br \/><span style=\"color: #0000ff\">HWADDR=$HWADDR<\/span><br \/><span style=\"color: #0000ff\">EOF<\/span><\/p>\n<p>2.\u00a0\u8ce6\u4e88\u57f7\u884c\u6b0a\u9650<br \/># <span style=\"color: #ff0000\">chmod 700 \/usr\/local\/bin\/set_static_ip<\/span><\/p>\n<p>3.\u00a0\u57f7\u884c<br \/># <span style=\"color: #ff0000\">\/usr\/local\/bin\/set_static_ip<\/span><\/p>\n<p>4. \u89c0\u770b\u6210\u679c<br \/># <span style=\"color: #ff0000\">cat \/etc\/sysconfig\/network<\/span><br \/><span style=\"color: #0000ff\">NETWORKING=yes<\/span><br \/><span style=\"color: #0000ff\">HOSTNAME=test.tces.ilc.edu.tw<\/span><br \/><span style=\"color: #0000ff\">GATEWAY=192.168.1.254<\/span><\/p>\n<p># <span style=\"color: #ff0000\">cat \/etc\/sysconfig\/network-scripts\/ifcfg-eth0<\/span><br \/><span style=\"color: #0000ff\">DEVICE=eth0<\/span><br \/><span style=\"color: #0000ff\">BOOTPROTO=static<\/span><br \/><span style=\"color: #0000ff\">IPADDR=192.168.1.6<\/span><br \/><span style=\"color: #0000ff\">NETMASK=255.255.255.0<\/span><br \/><span style=\"color: #0000ff\">ONBOOT=yes<\/span><br \/><span style=\"color: #0000ff\">HWADDR=6C:62:6D:61:80:81<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linux\u00a0\u5b89\u88dd\u5b8c\u6210\u4e4b\u5f8c\uff0c\u5982\u679c\u6c92\u6709\u5728\u624b\u52d5\u6216\u81ea\u52d5\u5b89\u88dd\u4e2d\u8a2d\u5b9a\u597d\u7db2\u8def\u7d44\u614b\uff0c\u901a\u5e38\u5c31\u8981\u624b\u52d5\u8a2d\u5b9a\u7db2\u8def\uff0c\u4f46\u5982\u679c\u662f\u7528\u7531 DHC &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/2blog.ilc.edu.tw\/25793\/2014\/02\/12\/%e7%94%b1-dhcp-server-%e7%9a%84%e5%8b%95%e6%85%8b-ip-%e8%bd%89%e6%88%90%e5%9b%ba%e5%ae%9a-ip-linux-server-%e7%af%87\/\" class=\"more-link\">\u95b1\u8b80\u5168\u6587<span class=\"screen-reader-text\">\u3008\u7531 DHCP Server \u7684\u52d5\u614b IP \u8f49\u6210\u56fa\u5b9a IP &#8211; Linux Server \u7bc7\u3009<\/span><\/a><\/p>\n","protected":false},"author":55,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[133,134],"tags":[],"class_list":["post-18188","post","type-post","status-publish","format-standard","hentry","category-c-78478","category-c-78479"],"meta_key":{"_encloseme":["1"],"lt_post_id":["470664"],"_pingme":["1"]},"_links":{"self":[{"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/posts\/18188"}],"collection":[{"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/users\/55"}],"replies":[{"embeddable":true,"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/comments?post=18188"}],"version-history":[{"count":1,"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/posts\/18188\/revisions"}],"predecessor-version":[{"id":19854,"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/posts\/18188\/revisions\/19854"}],"wp:attachment":[{"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/media?parent=18188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/categories?post=18188"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/tags?post=18188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}