{"id":1786,"date":"2024-04-16T17:00:13","date_gmt":"2024-04-16T09:00:13","guid":{"rendered":"https:\/\/airy.cn\/WordPress\/?p=1786"},"modified":"2024-04-16T17:00:13","modified_gmt":"2024-04-16T09:00:13","slug":"centos-%e6%b7%bb%e5%8a%a0%ef%bc%88%e6%b0%b8%e4%b9%85%ef%bc%89%e9%9d%99%e6%80%81%e8%b7%af%e7%94%b1%e7%9a%84%e6%96%b9%e6%b3%95%e6%80%bb%e7%bb%93","status":"publish","type":"post","link":"https:\/\/airy.cn\/WordPress\/?p=1786","title":{"rendered":"CentOS \u6dfb\u52a0\uff08\u6c38\u4e45\uff09\u9759\u6001\u8def\u7531\u7684\u65b9\u6cd5\u603b\u7ed3"},"content":{"rendered":"\n<p>\u8bf7\u8bbf\u95ee\u539f\u6587\u94fe\u63a5\uff1a<a href=\"https:\/\/sysin.org\/blog\/centos-static-route\/\">CentOS \u6dfb\u52a0\uff08\u6c38\u4e45\uff09\u9759\u6001\u8def\u7531\u7684\u65b9\u6cd5\u603b\u7ed3<\/a>\uff0c\u67e5\u770b\u6700\u65b0\u7248\u3002\u539f\u521b\u4f5c\u54c1\uff0c\u8f6c\u8f7d\u8bf7\u4fdd\u7559\u51fa\u5904\u3002<\/p>\n\n\n\n<p>\u5728\u65e5\u5e38\u4f7f\u7528\u4e2d\uff0c\u670d\u52a1\u5668\u6709\u4e24\u4e2a IP \u5730\u5740\uff0c\u4e24\u5757\u7f51\u5361\u7684\u914d\u7f6e\uff0c\u8bbf\u95ee\u4e0d\u540c\u7f51\u6bb5\uff0c\u8fd9\u79cd\u60c5\u51b5\u5f88\u5e38\u89c1\u3002\u4f46\u6211\u4eec\u9700\u8981\u521b\u5efa\u989d\u5916\u7684\u8def\u7531\u6761\u76ee\uff0c\u4ee5\u786e\u5b9a\u901a\u8fc7\u6b63\u786e\u7684\u7f51\u5173\u8f6c\u53d1\u6570\u636e\u5305\uff0c\u4f7f interface \u80fd\u591f\u6b63\u5e38\u901a\u4fe1\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0b\u5728 CentOS 7\u30018 \u6d4b\u8bd5\u901a\u8fc7<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u4e00\u3001\u4f7f\u7528-route-\u547d\u4ee4\u52a0\u5165\u4e34\u65f6\u8def\u7531\uff0c\u91cd\u542f\u540e\u5c06\u5931\u6548\"><a href=\"https:\/\/sysin.org\/blog\/centos-static-route\/#%E4%B8%80%E3%80%81%E4%BD%BF%E7%94%A8-route-%E5%91%BD%E4%BB%A4%E5%8A%A0%E5%85%A5%E4%B8%B4%E6%97%B6%E8%B7%AF%E7%94%B1%EF%BC%8C%E9%87%8D%E5%90%AF%E5%90%8E%E5%B0%86%E5%A4%B1%E6%95%88\"><\/a>\u4e00\u3001\u4f7f\u7528 route \u547d\u4ee4\u52a0\u5165\u4e34\u65f6\u8def\u7531\uff0c\u91cd\u542f\u540e\u5c06\u5931\u6548<\/h2>\n\n\n\n<p>route \u547d\u4ee4\u53c2\u6570\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>1<br>2<br>3<br>4<br>5<br>6<\/td><td>add \u589e\u52a0\u8def\u7531<br>del \u5220\u9664\u8def\u7531<br>-net \u8bbe\u7f6e\u5230\u67d0\u4e2a\u7f51\u6bb5\u7684\u8def\u7531<br>-host \u8bbe\u7f6e\u5230\u67d0\u53f0\u4e3b\u673a\u7684\u8def\u7531<br>gw \u51fa\u53e3\u7f51\u5173 IP \u5730\u5740<br>dev \u51fa\u53e3\u7f51\u5173 \u7269\u7406\u8bbe\u5907\u540d<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9<br>10<br>11<br>12<br>13<br>14<br>15<br>16<\/td><td># \u52a0\u5165\u5230\u4e3b\u673a\u7684\u8def\u7531 (sysin)<br>route add -host 192.168.1.123 dev eth0<br>route add -host 192.168.1.123 gw 192.168.1.1<br><br># \u52a0\u5165\u5230\u7f51\u7edc\u7684\u8def\u7531<br>route add -net 192.168.1.123 netmask 255.255.255.0 eth0<br>route add -net 192.168.1.123 netmask 255.255.255.0 gw 192.168.1.1<br>route add -net 192.168.1.123 netmask 255.255.255.0 gw 192.168.1.1 eth1<br>route add -net 192.168.1.0\/24 eth1<br><br># \u52a0\u5165\u9ed8\u8ba4\u7f51\u5173<br>route add default gw 192.168.1.1<br><br># \u5220\u9664\u8def\u7531<br>route del -host 192.168.1.11 dev eth0<br>route del -net 192.168.1.123 netmask 255.255.255.0<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>1<br>2<br>3<\/td><td># \u67e5\u770b\u8def\u7531\u4fe1\u606f<br>ip route<br>route -n<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u4e8c\u3001\u5728-Linux-\u4e2d\u6dfb\u52a0\u6c38\u4e45\u8def\u7531\u7684\u65b9\u6cd5\"><a href=\"https:\/\/sysin.org\/blog\/centos-static-route\/#%E4%BA%8C%E3%80%81%E5%9C%A8-Linux-%E4%B8%AD%E6%B7%BB%E5%8A%A0%E6%B0%B8%E4%B9%85%E8%B7%AF%E7%94%B1%E7%9A%84%E6%96%B9%E6%B3%95\"><\/a>\u4e8c\u3001\u5728 Linux \u4e2d\u6dfb\u52a0\u6c38\u4e45\u8def\u7531\u7684\u65b9\u6cd5<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"1-\u9ed8\u8ba4\u7f51\u5173\"><a href=\"https:\/\/sysin.org\/blog\/centos-static-route\/#1-%E9%BB%98%E8%AE%A4%E7%BD%91%E5%85%B3\"><\/a>1. \u9ed8\u8ba4\u7f51\u5173<\/h3>\n\n\n\n<p>\uff081\uff09\u5199\u5165 ifcfg \u6587\u4ef6\uff08\u63a8\u8350\uff09<\/p>\n\n\n\n<p><code>vi \/etc\/sysconfig\/network-scripts\/ifcfg-eth0<\/code><\/p>\n\n\n\n<p>\u5728\u914d\u7f6e ip \u5730\u5740\u7684\u65f6\u5019\u76f4\u63a5\u5c06 GATEWAY \u7684\u914d\u7f6e\u5199\u5165 ifcfg \u6587\u4ef6\u3002\u5f62\u5f0f\uff1aGATEWAY=gw-ip<\/p>\n\n\n\n<p>\u9002\u5408\u52a0\u5165\u9ed8\u8ba4\u8def\u7531<\/p>\n\n\n\n<p>\uff082\uff09\u5728&nbsp;<code>\/etc\/sysconfig\/network<\/code>&nbsp;\u91cc\u52a0\u5165\u5230\u6587\u4ef6\u672b\u5c3e\uff0c\u683c\u5f0f\u4f8b\u5982\u4ee5\u4e0b\uff1a<\/p>\n\n\n\n<p>GATEWAY=gw-ip \u6216\u8005 GATEWAY=gw-dev<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"2-\u5199\u5165-etc-rc-loacl\uff08\u4e0d\u63a8\u8350\uff09\"><a href=\"https:\/\/sysin.org\/blog\/centos-static-route\/#2-%E5%86%99%E5%85%A5-etc-rc-loacl%EF%BC%88%E4%B8%8D%E6%8E%A8%E8%8D%90%EF%BC%89\"><\/a>2. \u5199\u5165&nbsp;<code>\/etc\/rc.loacl<\/code>\uff08\u4e0d\u63a8\u8350\uff09<\/h3>\n\n\n\n<p>\uff08\u6ce8\u610f\uff1aCentOS 7 \u5fc5\u987b\u6267\u884c&nbsp;<code>chmod +x \/etc\/rc.d\/rc.local<\/code>&nbsp;\u6765\u786e\u4fdd\u786e\u4fdd\u8fd9\u4e2a\u811a\u672c\u5728\u5f15\u5bfc\u65f6\u6267\u884c\u3002\uff09<\/p>\n\n\n\n<p>\u80fd\u591f\u5c06\u4e0a\u9762\u63d0\u5230\u7684\u547d\u4ee4\u5199\u5165&nbsp;<code>\/etc\/rc.local<\/code>&nbsp;\u6587\u4ef6\u91cc\uff0c\u8fd9\u6837\u5728\u7cfb\u7edf\u542f\u52a8\u7684\u65f6\u5019\u4f1a\u81ea\u5df1\u4e3b\u52a8\u589e\u52a0\u76f8\u5173\u7684\u8def\u7531\u8bbe\u7f6e\u3002<\/p>\n\n\n\n<p>\u53ea\u662f\u8fd9\u6837\u7684\u65b9\u6cd5\u6709\u4e00\u4e2a\u7f3a\u70b9 (sysin)\uff1a\u5047\u8bbe\u67d0\u4e2a\u7cfb\u7edf\u670d\u52a1\uff0c\u6bd4\u65b9\u8bf4\u662f NFS \u670d\u52a1\uff0c\u8fd9\u4e2a\u670d\u52a1\u662f\u5728\u542f\u52a8 network \u670d\u52a1\u4e4b\u540e\uff0c\u5728\u8fd0\u884c rc.local \u4e4b\u524d\uff0c\u5047\u8bbe\u4f60\u8bbe\u7f6e\u7684\u6709\u81ea\u5df1\u4e3b\u52a8\u6302\u8f7d\u7684 nfs\u3002\u90a3\u4e48\uff0c\u8fd9\u91cc\u94fe\u8def\u7684\u4e0d\u901a\u7545\u3002\u4f1a\u9020\u6210\u6302\u8f7d\u7684\u5931\u8d25\u3002\u53e6\u5916\u4e00\u4e2a\u5c31\u662f\u5047\u8bbe\u4f60\u91cd\u65b0\u542f\u52a8\u4e86\u7f51\u7edc server\uff0c\u90a3\u4e48\u8def\u7531\u5c31\u5931\u6548\u4e86\uff0c\u8fd9\u4e2a\u65f6\u5019\u4f60\u4e0d\u5f97\u4e0d\u53c8\u4e00\u6b21\u8f7d\u5165\u8fd9\u4e2a\u6587\u4ef6\uff0c\u53ef\u662f\u5047\u8bbe\u4f60\u662f\u8fdc\u7a0b\u64cd\u4f5c\u7684\u5462\uff1f\u6240\u4ee5\uff0c\u8fd9\u79cd\u65b9\u6cd5\u4e0d\u63a8\u8350\u3002<\/p>\n\n\n\n<p>\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<p>\u7f16\u8f91&nbsp;<code>\/etc\/rc.local<\/code>\uff0c\u4f7f\u7528 route \u547d\u4ee4\u8bed\u6cd5\u6dfb\u52a0<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>1<br>2<br>3<\/td><td>route add -net 192.168.3.0\/24 dev eth0<br>route add -net 192.168.2.0\/24 gw 192.168.3.254<br>route add -net 172.16.0.0 netmask 255.255.0.0 gw 192.168.1.100 dev eth0<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u4fee\u6539\u8fc7\u7684\u6587\u4ef6&nbsp;<code>\/etc\/rc.d\/rc.local<\/code>&nbsp;\u6587\u4ef6\u793a\u4f8b<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9<\/td><td>#!\/bin\/sh<br>#<br># This script will be executed *after* all the other init scripts.<br># You can put your own initialization stuff in here if you don&#8217;t<br># want to do the full Sys V style init stuff.<br>touch \/var\/lock\/subsys\/local<br>route add -net 192.168.3.0\/24 dev eth0<br>route add -net 192.168.2.0\/24 gw 192.168.3.254<br>route add -net 172.16.0.0 netmask 255.255.0.0 gw 192.168.1.100 dev eth0<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"3-\u5199\u5165-etc-sysconfig-static-routes-\u6587\u4ef6\"><a href=\"https:\/\/sysin.org\/blog\/centos-static-route\/#3-%E5%86%99%E5%85%A5-etc-sysconfig-static-routes-%E6%96%87%E4%BB%B6\"><\/a>3. \u5199\u5165&nbsp;<code>\/etc\/sysconfig\/static-routes<\/code>&nbsp;\u6587\u4ef6<\/h3>\n\n\n\n<p>\u9ed8\u8ba4\u5728&nbsp;<code>\/etc\/sysconifg<\/code>&nbsp;\u6587\u4ef6\u5939\u4e2d\u662f\u6ca1\u6709\u8fd9\u4e2a\u6587\u4ef6\u7684\uff0c\u987b\u8981\u6211\u4eec\u624b\u5de5\u521b\u5efa\u3002\u5bf9\u8fd9\u4e2a\u6587\u4ef6\u7684\u8c03\u7528\u5728\u4ee5\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9<br>10<br>11<br>12<\/td><td>cat \/etc\/init.d\/network<br><br># Add non interface-specific static-routes.<br>if [-f \/etc\/sysconfig\/static-routes]; then<br>if [-x \/sbin\/route]; then<br>grep &#8220;^any&#8221; \/etc\/sysconfig\/static-routes | while read ignore args ; do<br>\/sbin\/route add -$args<br>done<br>else<br>net_log $&#8221;Legacy static-route support not available: \/sbin\/route not found&#8221;<br>fi<br>fi<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u6dfb\u52a0\u64cd\u4f5c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>1<br>2<br>3<br>4<br>5<\/td><td>vi \/etc\/sysconfig\/static-routes<br>any net 192.168.1.0\/24 gw 192.168.1.1<br>any net 192.168.2.0 netmask 255.255.255.0 gw 192.168.2.1<br>any host 10.19.190.11\/32 gw 10.19.177.10<br>any host 10.19.190.12 gw 10.19.177.10<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u8fd9\u6837\u7684\u65b9\u5f0f\u7684\u8bdd\uff0c\u548c rc.local \u76f8\u6bd4\uff0c\u6bd4\u8f83\u6709\u7528\u3002\u8fd8\u6bd4\u65b9 nfs\uff0c\u8fd9\u4e2a\u8def\u7531\u7684\u751f\u6548\u65f6\u95f4\u662f\u5728\u7f51\u7edc\u670d\u52a1 network \u542f\u52a8\u7684\u65f6\u5019\u751f\u6548\u7684\uff0c\u800c\u5176\u5b83\u7684\u4e00\u4e9b\u7f51\u7edc\u76f8\u5173\u670d\u52a1\u90fd\u662f\u5728\u7f51\u7edc\u670d\u52a1\u542f\u52a8\u6210\u529f\u4e4b\u540e\u518d\u542f\u52a8\u7684\uff0c\u6240\u4ee5\u53ef\u4ee5\u4fdd\u8bc1\u7f51\u7edc\u94fe\u8def\u7684\u901a\u7545\u3002\u5e76\u4e14\uff0c\u5047\u8bbe\u6211\u91cd\u65b0\u542f\u52a8\u4e86\u7f51\u7edc\u670d\u52a1\uff0c\u8fd9\u4e2a\u811a\u672c\u662f\u5728\u7f51\u7edc\u670d\u52a1\u542f\u52a8\u91cc\u9762\u7684\u811a\u672c\u8c03\u7528\u3002\u56e0\u6b64\uff0c\u4e5f\u589e\u52a0\u4e86\u81ea\u5df1\u4e3b\u52a8\u4e0a\u8bbe\u7f6e\u7684\u76f8\u5173\u8def\u7ebf\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u8be5\u65b9\u5f0f\u5728 CentOS 8 \u9ed8\u8ba4\u5b89\u88c5\u65f6\u65e0\u6548\u3002<\/p>\n\n\n\n<p>\u5728 CentOS 8 \u4e2d\u9ed8\u8ba4\u4f7f\u7528 nmcli \u7ba1\u7406\u7f51\u7edc\uff0c\u53ef\u4ee5\u901a\u8fc7&nbsp;<code>yum install network-scripts<\/code>&nbsp;\u6765\u5b89\u88c5\u4f20\u7edf\u7684 network.service\uff0c\u6062\u590d\u7528\u8fd9\u79cd\u65b9\u5f0f\u914d\u7f6e\u9759\u6001\u8def\u7531\u3002<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"4-\u521b\u5efa-etc-sysconfig-network-scripts-route-eth0\uff08\u63a8\u8350\uff09\"><a href=\"https:\/\/sysin.org\/blog\/centos-static-route\/#4-%E5%88%9B%E5%BB%BA-etc-sysconfig-network-scripts-route-eth0%EF%BC%88%E6%8E%A8%E8%8D%90%EF%BC%89\"><\/a>4. \u521b\u5efa&nbsp;<code>\/etc\/sysconfig\/network-scripts\/route-eth0<\/code>\uff08\u63a8\u8350\uff09<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>1<br>2<br>3<br>4<br>5<br>6<\/td><td># \u5728 `\/etc\/sysconfig\/network-scripts\/` \u76ee\u5f55\u4e0b\u521b\u5efa\u540d\u4e3a route-eth0 \u7684\u6587\u4ef6<br>vi \/etc\/sysconfig\/network-scripts\/route-eth0<br># \u5728\u6b64\u6587\u4ef6\u6dfb\u52a0\u5982\u4e0b\u683c\u5f0f\u7684\u5185\u5bb9<br>192.168.1.0\/24 via 192.168.0.1<br># \u91cd\u542f\u7f51\u7edc\u9a8c\u8bc1\u6709\u6548<br>systemctl restart network<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u8bf7\u8bbf\u95ee\u539f\u6587\u94fe\u63a5\uff1aCentOS \u6dfb\u52a0\uff08\u6c38\u4e45\uff09\u9759\u6001\u8def\u7531\u7684\u65b9\u6cd5\u603b\u7ed3\uff0c\u67e5\u770b\u6700\u65b0\u7248\u3002\u539f\u521b\u4f5c\u54c1\uff0c\u8f6c\u8f7d\u8bf7\u4fdd\u7559\u51fa\u5904\u3002 \u5728\u65e5\u5e38\u4f7f &#8230; <a title=\"CentOS \u6dfb\u52a0\uff08\u6c38\u4e45\uff09\u9759\u6001\u8def\u7531\u7684\u65b9\u6cd5\u603b\u7ed3\" class=\"read-more\" href=\"https:\/\/airy.cn\/WordPress\/?p=1786\" aria-label=\"\u9605\u8bfb CentOS \u6dfb\u52a0\uff08\u6c38\u4e45\uff09\u9759\u6001\u8def\u7531\u7684\u65b9\u6cd5\u603b\u7ed3\">\u9605\u8bfb\u66f4\u591a<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kadence_starter_templates_imported_post":false,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-1786","post","type-post","status-publish","format-standard","hentry","category-airy-tech"],"_links":{"self":[{"href":"https:\/\/airy.cn\/WordPress\/index.php?rest_route=\/wp\/v2\/posts\/1786","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/airy.cn\/WordPress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/airy.cn\/WordPress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/airy.cn\/WordPress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/airy.cn\/WordPress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1786"}],"version-history":[{"count":1,"href":"https:\/\/airy.cn\/WordPress\/index.php?rest_route=\/wp\/v2\/posts\/1786\/revisions"}],"predecessor-version":[{"id":1787,"href":"https:\/\/airy.cn\/WordPress\/index.php?rest_route=\/wp\/v2\/posts\/1786\/revisions\/1787"}],"wp:attachment":[{"href":"https:\/\/airy.cn\/WordPress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/airy.cn\/WordPress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/airy.cn\/WordPress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}