{"id":1107,"date":"2022-06-24T16:11:41","date_gmt":"2022-06-24T08:11:41","guid":{"rendered":"https:\/\/aichh.com\/?p=1107"},"modified":"2022-06-24T16:59:44","modified_gmt":"2022-06-24T08:59:44","slug":"1107","status":"publish","type":"post","link":"https:\/\/aichh.com\/1107.html","title":{"rendered":"centos8\u4e4b\u7f51\u5361\u914d\u7f6e\u4fee\u6539\u53ca\u7ba1\u7406"},"content":{"rendered":"<!--wp-compress-html--><!--wp-compress-html no compression--><p>\u4e00\u3001\u60c5\u51b5\u8bf4\u660e<br \/>\ncentos8\u7684\u7f51\u5361\u670d\u52a1\u4e0ecentos7\u6709\u6240\u4e0d\u540c\uff0c\u65e0\u6cd5\u901a\u8fc7systemctl\u6216\u8005service\u547d\u4ee4\u91cd\u542f\u7f51\u5361\u3002centos8\u7f51\u5361\u670d\u52a1\u7531nmcli\u8fdb\u884c\u7ba1\u7406\u3002<\/p>\n<pre>\r\n[root@centos8 network-scripts]# systemctl restart network\r\nFailed to restart network.service: Unit network.service not found.\r\n[root@centos8 network-scripts]# service network restart\r\nRedirecting to \/bin\/systemctl restart network.service\r\nFailed to restart network.service: Unit network.service not found.<\/pre>\n<p>\u4e8c\u3001\u7f51\u5361\u914d\u7f6e<br \/>\n1\u3001\u8fdb\u5165\u7f51\u5361\u914d\u7f6e\u76ee\u5f55<\/p>\n<pre>[root@centos8 ~]# cd \/etc\/sysconfig\/network-scripts\/\r\n[root@centos8 network-scripts]# ll\r\ntotal 4\r\n-rw-r\u2013r--. 1 root root 366 Mar 4 22:35 ifcfg-ens33<\/pre>\n<p>2\u3001\u7f16\u8f91\u7f51\u5361\u914d\u7f6e\u6587\u4ef6<\/p>\n<pre>[root@centos8 network-scripts]# vim ifcfg-ens33<\/pre>\n<p>\u5c06BOOTPROTO\u53c2\u6570\u7531dhcp\u6539\u4e3astatic\uff0c\u6839\u636e\u9700\u8981\u914d\u7f6eIP\u5730\u5740\u3001\u63a9\u7801\u3001\u7f51\u5173\u3001DNS\u7b49\u4fe1\u606f<\/p>\n<pre>BOOTPROTO=static\r\nIPADDR=192.168.0.127\r\nNETMASK=255.255.255.0\r\nGATEWAY=192.168.0.1\r\nDNS1=114.114.114.114<\/pre>\n<p>3\u3001\u91cd\u8f7d\u7f51\u5361\u914d\u7f6e<\/p>\n<pre>[root@centos8 network-scripts]# nmcli c reload ens33<\/pre>\n<p>4\u3001\u91cd\u542f\u7f51\u5361<\/p>\n<pre>[root@centos8 network-scripts]# nmcli c up ens33\r\nConnection successfully activated (D-Bus active path: \/org\/freedesktop\/NetworkManager\/ActiveConnection\/8)<\/pre>\n<p>5\u3001\u9a8c\u8bc1\u7f51\u7edc<\/p>\n<pre>[root@centos8 network-scripts]# ping www.baidu.com\r\nPING www.a.shifen.com (183.232.231.174) 56(84) bytes of data.\r\n64 bytes from localhost (183.232.231.174): icmp_seq=1 ttl=52 time=18.8 ms\r\n64 bytes from localhost (183.232.231.174): icmp_seq=2 ttl=52 time=18.2 ms\r\n^C\r\n\u2014 www.a.shifen.com ping statistics \u2014\r\n2 packets transmitted, 2 received, 0% packet loss, time 4ms\r\nrtt min\/avg\/max\/mdev = 18.228\/18.503\/18.779\/0.307 ms<\/pre>\n<p>\u4e09\u3001nmcli\u547d\u4ee4\u7ba1\u7406\u7f51\u5361<br \/>\n1\u3001\u67e5\u770b\u7f51\u5361\u4fe1\u606f<\/p>\n<pre>[root@centos8 network-scripts]# nmcli connection\r\nNAME UUID TYPE DEVICE\r\nens33 2cf75158-1e14-46c8-be85-b3d9cd0e8352 ethernet ens33\r\nvirbr0 9902a052-4775-434a-9531-62712a3be9c3 bridge virbr0<\/pre>\n<p>2\u3001\u663e\u793a\u5177\u4f53\u7684\u7f51\u7edc\u63a5\u53e3\u4fe1\u606f<\/p>\n<pre>[root@centos8 network-scripts]# nmcli connection show ens33\r\nconnection.id: ens33\r\nconnection.uuid: 2cf75158-1e14-46c8-be85-b3d9cd0e8352\r\nconnection.stable-id: \u2013\r\nconnection.type: 802-3-ethernet\r\nconnection.interface-name: ens33\r\nconnection.autoconnect: yes\r\n\u2026<\/pre>\n<p>3\u3001\u663e\u793a\u6240\u6709\u6d3b\u52a8\u8fde\u63a5<\/p>\n<pre>[root@centos8 network-scripts]# nmcli connection show --active\r\nNAME UUID TYPE DEVICE\r\nens33 2cf75158-1e14-46c8-be85-b3d9cd0e8352 ethernet ens33\r\nvirbr0 9902a052-4775-434a-9531-62712a3be9c3 bridge virbr0<\/pre>\n<p>4\u3001\u6dfb\u52a0\u4e00\u4e2a\u7f51\u5361<\/p>\n<pre>[root@centos8 network-scripts]# nmcli connection add type ethernet con-name eth0\r\nConnection \u2018eth0\u2019 (28f1b3d6-4f13-41a3-a809-1c82fd2f470f) successfully added.<\/pre>\n<p>5\u3001\u5220\u9664\u4e00\u4e2a\u7f51\u5361\u8fde\u63a5<\/p>\n<pre>[root@centos8 network-scripts]# nmcli connection delete virbr0\r\nConnection \u2018virbr0\u2019 (9902a052-4775-434a-9531-62712a3be9c3) successfully deleted.<\/pre>\n<p>6\u3001\u7ed9\u6dfb\u52a0\u4e00\u4e2aIP\uff08IPADDR\uff09<\/p>\n<pre>[root@centos8 network-scripts]# nmcli connection modify eth0 ipv4.addresses 192.168.10.100<\/pre>\n<p>7\u3001\u7ed9xxx\u6dfb\u52a0\u4e00\u4e2a\u5b50\u7f51\u63a9\u7801\uff08NETMASK\uff09<\/p>\n<pre>[root@centos8 network-scripts]# nmcli connection modify eth0 ipv4.addresses 192.168.10.100\/24<\/pre>\n<p>8\u3001\u6dfb\u52a0\u4e00\u4e2aipv4<br \/>\n\u6b64\u5904\u53c2\u6570\u4e3a+ipv4.addresses\uff0c\u5373\u5728\u6b64\u539f\u6765\u7684\u914d\u7f6e\u4e0a\u6dfb\u52a0\u4e00\u4e2a\u5730\u5740\u914d\u7f6e\uff0c\u65e0+\u5219\u662f\u5728\u539f\u6765\u7684\u57fa\u7840\u4e0a\u4fee\u6539IP\u5730\u5740\u3002<\/p>\n<pre>[root@centos8 network-scripts]# nmcli connection modify eth0 +ipv4.addresses 192.168.30.100\/24<\/pre>\n<p>9\u3001\u5220\u9664\u4e00\u4e2aipv4<\/p>\n<pre>[root@centos8 network-scripts]# nmcli connection modify eth0 -ipv4.addresses 192.168.20.100\/24<\/pre>\n<p>10\u3001\u6dfb\u52a0DNS<\/p>\n<pre>[root@centos8 network-scripts]# nmcli connection modify eth0 +ipv4.dns 211.142.211.124<\/pre>\n<p>11\u3001\u5220\u9664DNS<\/p>\n<pre>[root@centos8 network-scripts]# nmcli connection modify eth0 -ipv4.dns 114.114.114.114<\/pre>\n<p>12\u3001\u6dfb\u52a0\u4e00\u4e2a\u7f51\u5173\uff08GATEWAY\uff09<\/p>\n<pre>[root@centos8 network-scripts]# nmcli connection modify eth0 ipv4.gateway 192.168.0.1<\/pre>\n<p>13\u3001\u4f7f\u7528nmcli\u91cd\u65b0\u56de\u8f7d\u7f51\u7edc\u914d\u7f6e<\/p>\n<pre>[root@centos8 network-scripts]# nmcli c reload<\/pre>\n<p>\u5982\u679c\u4e4b\u524d\u6ca1\u6709xxx\u7684connection\uff0c\u5219\u4e0a\u4e00\u6b65reload\u540e\u5c31\u5df2\u7ecf\u81ea\u52a8\u751f\u6548\u4e86<\/p>\n<p>14\u3001\u91cd\u542f\u7f51\u5361<\/p>\n<pre>[root@centos8 network-scripts]# nmcli c up ens33\r\nConnection successfully activated (D-Bus active path: \/org\/freedesktop\/NetworkManager\/ActiveConnection\/11)<\/pre>\n<p>15\u3001\u4e0b\u7ebf\u7f51\u5361<\/p>\n<pre>[root@centos8 network-scripts]# nmcli c down ens33<\/pre>\n<p>\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<\/p>\n<p>\u539f\u6587\u94fe\u63a5\uff1ahttps:\/\/blog.csdn.net\/carefree2005\/article\/details\/114396600<\/p>\n<!--wp-compress-html no compression--><!--wp-compress-html-->","protected":false},"excerpt":{"rendered":"\u4e00\u3001\u60c5\u51b5\u8bf4\u660e centos8\u7684\u7f51\u5361\u670d\u52a1\u4e0ecentos7\u6709\u6240\u4e0d\u540c\uff0c\u65e0\u6cd5\u901a\u8fc7systemctl\u6216\u8005service\u547d\u4ee4\u91cd\u542f\u7f51\u5361\u3002centos8\u7f51\u5361\u670d\u52a1\u7531nmcli\u8fdb\u884c\u7ba1\u7406\u3002 [root@centos8 ne \u00b7\u00b7\u00b7","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[28,287,107],"class_list":["post-1107","post","type-post","status-publish","format-standard","hentry","category-jiaocheng","tag-centos","tag-network","tag-service"],"views":624,"_links":{"self":[{"href":"https:\/\/aichh.com\/api\/wp\/v2\/posts\/1107","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aichh.com\/api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aichh.com\/api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aichh.com\/api\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aichh.com\/api\/wp\/v2\/comments?post=1107"}],"version-history":[{"count":3,"href":"https:\/\/aichh.com\/api\/wp\/v2\/posts\/1107\/revisions"}],"predecessor-version":[{"id":1114,"href":"https:\/\/aichh.com\/api\/wp\/v2\/posts\/1107\/revisions\/1114"}],"wp:attachment":[{"href":"https:\/\/aichh.com\/api\/wp\/v2\/media?parent=1107"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aichh.com\/api\/wp\/v2\/categories?post=1107"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aichh.com\/api\/wp\/v2\/tags?post=1107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}