{"id":203131,"date":"2020-10-19T08:59:16","date_gmt":"2020-10-19T00:59:16","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=203131"},"modified":"2020-10-15T15:59:54","modified_gmt":"2020-10-15T07:59:54","slug":"linux-add-vlan","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-add-vlan.html","title":{"rendered":"\u5982\u4f55\u5728Linux\u4e0a\u5212\u5206VLAN"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5728\u67d0\u4e9b\u573a\u666f\u4e2d\uff0c\u6211\u4eec\u5e0c\u671b\u5728Linux\u670d\u52a1\u5668(CentOS \/ RHEL)\u4e0a\u7684\u540c\u4e00\u7f51\u5361\u5206\u914d\u6765\u81ea\u4e0d\u540cVLAN\u7684\u591a\u4e2aip\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u542f\u7528VLAN\u6807\u8bb0\u63a5\u53e3\u6765\u5b9e\u73b0\uff0c\u4f46\u8981\u5b9e\u73b0\u8fd9\u4e00\u70b9\uff0c\u9996\u5148\u5fc5\u987b\u786e\u4fdd\u4ea4\u6362\u673a\u4e0a\u6dfb\u52a0\u591a\u4e2avlan\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2aLinux\u670d\u52a1\u5668\uff0c\u5176\u4e2d\u6709\u4e24\u4e2a\u4ee5\u592a\u7f51\u5361(ens33\u548cens38)\uff0c\u7b2c\u4e00\u4e2a\u7f51\u5361(ens33)\u7528\u4e8e\u6570\u636e\u6d41\u91cf\uff0c\u7b2c\u4e8c\u4e2a\u7f51\u5361(ens38)\u7528\u4e8e\u63a7\u5236\/\u7ba1\u7406\u6d41\u91cf\u3002\u5bf9\u4e8e\u6570\u636e\u6d41\uff0c\u5c06\u4f7f\u7528\u591a\u4e2avlan(\u5c06\u5728\u6570\u636e\u6d41\u7f51\u5361\u4e0a\u5206\u914d\u6765\u81ea\u4e0d\u540cvlan\u7684\u591a\u4e2aip)\u3002<\/p>\n

\u5047\u8bbe\u4ece\u4ea4\u6362\u673a\u8fde\u63a5\u5230\u670d\u52a1\u5668\u6570\u636e\u6d41\u91cf\u7f51\u5361\u7684\u7aef\u53e3\u88ab\u914d\u7f6e\u4e3aTrunk\uff0c\u901a\u8fc7\u6620\u5c04\u591a\u4e2avlan\u5230\u5b83\u3002\u4e0b\u9762\u662f\u6620\u5c04\u5230\u6570\u636e\u6d41\u91cf\u7f51\u5361\u7684vlan:<\/p>\n

    \n
  • VLAN ID (200)\uff0c172.168.10.0\/24<\/li>\n
  • VLAN ID (300)\uff0c172.168.20.0\/24<\/li>\n<\/ul>\n

    \u5728CentOS 7 \/RHEL 7 \/ CentOS 8 \/RHEL 8\u7cfb\u7edf\u4e0a\u4f7f\u7528VLAN\u6807\u8bb0\u63a5\u53e3\uff0c\u5fc5\u987b\u52a0\u8f7d\u5185\u6838\u6a21\u57578021q\u3002
    \n\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u52a0\u8f7d\u5185\u6838\u6a21\u5757\u201c8021q\u201d<\/p>\n

    \r\n# \u5148\u5217\u51fa\u6a21\u5757\uff0c\u53d1\u73b0\u6ca1\u67098021q\u6a21\u5757\u3002\r\n[root@localhost ~]# lsmod | grep -i 8021q\r\n# \u52a0\u8f7d\u6a21\u5757\r\n[root@localhost ~]# modprobe --first-time 8021q\r\n[root@localhost ~]# lsmod | grep -i 8021q\r\n8021q                  33080  0 \r\ngarp                   14384  1 8021q\r\nmrp                    18542  1 8021q\r\n<\/pre>\n

    \u4f7f\u7528modinfo<\/code>\u547d\u4ee4\u5217\u51fa8021q\u7684\u4fe1\u606f\uff1a<\/p>\n

    \r\n[root@localhost ~]# modinfo 8021q\r\n<\/pre>\n

    \"\"
    \n\u73b0\u5728\u4f7f\u7528ip\u547d\u4ee4\u521b\u5efavlan 200\u548cvlan 300\u5230ens33\u7f51\u5361\uff1a<\/p>\n

    \r\n# \u521b\u5efavlan 200\u548cvlan 300\r\n[root@localhost ~]# ip link add link ens33 name ens33.200 type vlan id 200\r\n[root@localhost ~]# ip link add link ens33 name ens33.300 type vlan id 300\r\n<\/pre>\n

    \"\"
    \n\u53d1\u73b0ens33.200\u548cens33.300\u7684\u94fe\u8def\u72b6\u6001\u4e3aDOWN\uff0c\u4e0b\u9762\u542f\u7528\u5b83\u4eec\u3002<\/p>\n

    \r\n# \u542f\u7528vlan 200 \u548cvlan 300\r\n[root@localhost ~]# ip link set ens33.200 up\r\n[root@localhost ~]# ip link set ens33.300 up\r\n<\/pre>\n

    \"\"
    \n\u4e0b\u9762\u4e3a\u4e24\u4e2avlan \u5206\u914dip\u5730\u5740\uff1a<\/p>\n

    \r\n[root@localhost ~]# ip address add 172.168.10.51\/24 dev ens33.200\r\n[root@localhost ~]# ip address add 172.168.20.51\/24 dev ens33.300\r\n<\/pre>\n

    \"\"
    \n\u53ef\u4ee5\u770b\u5230ens33.200\u548cens33.300\u5df2\u7ecf\u914d\u7f6e\u597dip\u5730\u5740\u4e86\u3002<\/p>\n

    \u4f46\u662f\u4e0a\u9762\u4f7f\u7528ip address\u6dfb\u52a0\u7684VLAN\u548c\u5730\u5740\u4e0d\u4f1a\u6c38\u4e45\u751f\u6548\u7684\u3002\u91cd\u542f\u7cfb\u7edf\u4e4b\u540e\u90fd\u4e0d\u5b58\u5728\u4e86\u3002\u6211\u4eec\u9700\u8981\u628a\u8fd9\u4e9b\u914d\u7f6e\u4fdd\u5b58\u5728\u914d\u7f6e\u6587\u4ef6\u91cc\u9762\u3002<\/p>\n

    \u9996\u5148\u4fee\u6539ifcfg-ens33\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u5176\u6b21\u521b\u5efaifcfg-ens33.200\u548cifcfg-ens33.300\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n

    \r\n[root@localhost ~]# vim \/etc\/sysconfig\/network-scripts\/ifcfg-ens33 \r\n\r\nTYPE=Ethernet\r\nBOOTPROTO=none\r\nDEVICE=ens33\r\nONBOOT=yes\r\n\r\n<\/pre>\n

    \u63a5\u4e0b\u6765\u4e3avlan 200\u521b\u5efa\u914d\u7f6e\u6587\u4ef6\uff0c\u547d\u540d\u4e3aifcfg-ens33.200<\/p>\n

    \r\n[root@localhost ~]# vim \/etc\/sysconfig\/network-scripts\/ifcfg-ens33.200\r\n\r\nDEVICE=ens33.200\r\nBOOTPROTO=none\r\nONBOOT=yes\r\nIPADDR=172.168.10.51\r\nPREFIX=24\r\nNETWORK=172.168.10.0\r\nVLAN=yes\r\n<\/pre>\n

    \u63a5\u4e0b\u6765\u4e3avlan 300\u521b\u5efa\u914d\u7f6e\u6587\u4ef6\uff0c\u547d\u540d\u4e3aifcfg-ens33.300<\/p>\n

    \r\n[root@localhost ~]# vim \/etc\/sysconfig\/network-scripts\/ifcfg-ens33.300\r\n\r\nDEVICE=ens33.300\r\nBOOTPROTO=none\r\nONBOOT=yes\r\nIPADDR=172.168.20.51\r\nPREFIX=24\r\nNETWORK=172.168.20.0\r\nVLAN=yes\r\n<\/pre>\n

    \u7f16\u8f91\u5b8c\u914d\u7f6e\u6587\u4ef6\uff0c\u91cd\u542f\u4e00\u4e0b\u7f51\u7edc\u670d\u52a1\u3002<\/p>\n

    \r\n[root@localhost ~]# systemctl restart network\r\n<\/pre>\n

    \"\"
    \n\u53ef\u4ee5\u770b\u5230vlan200,300\u7684\u4fe1\u606f\u90fd\u6ca1\u6709\u6d88\u5931\u3002<\/p>\n

    \u603b\u7ed3<\/strong><\/div>\n

    \u5728\u67d0\u4e9b\u573a\u666f\u4e2d\uff0c\u6211\u4eec\u5e0c\u671b\u5728Linux\u670d\u52a1\u5668(CentOS \/ RHEL)\u4e0a\u7684\u540c\u4e00\u7f51\u5361\u5206\u914d\u6765\u81ea\u4e0d\u540cVLAN\u7684\u591a\u4e2aip\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u542f\u7528VLAN\u6807\u8bb0\u63a5\u53e3\u6765\u5b9e\u73b0\uff0c\u4f46\u8981\u5b9e\u73b0\u8fd9\u4e00\u70b9\uff0c\u9996\u5148\u5fc5\u987b\u786e\u4fdd\u4ea4\u6362\u673a\u4e0a\u6dfb\u52a0\u591a\u4e2avlan\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

    \u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2aLinux\u670d\u52a1\u5668\uff0c\u5176\u4e2d\u6709\u4e24\u4e2a\u4ee5\u592a\u7f51\u5361(ens33\u548cens38)\uff0c\u7b2c\u4e00\u4e2a\u7f51\u5361(ens33)\u7528\u4e8e\u6570\u636e […]<\/p>\n","protected":false},"author":309,"featured_media":203132,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-203131","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\/203131","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\/309"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=203131"}],"version-history":[{"count":1,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/203131\/revisions"}],"predecessor-version":[{"id":203138,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/203131\/revisions\/203138"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/203132"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=203131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=203131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=203131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}