CentOS 配置网络连接(包括添加多个 IP 方法)

Kevin 教程 1,725 次浏览 51条评论

如果没有在 CentOS 安装过程中配置网络,之后需要手动修改网卡配置文件,设置静态 IP 地址和子网掩码(外网访问须同时设置网关和 DNS),相关信息可以从主机商处获取。下面介绍具体设置方法。


ip address show命令列出现有网卡及其 IP。如果输出内容太多,可用ip address show | less分页查看。| 垂直线用 Shift + \ 组合键打出。less 用 Ctrl + FCtrl + B 前后翻页,q 退出。


cd /etc/sysconfig/network-scripts && ls

示例输出,ifcfg-xxx就是网卡配置文件ifcfg-lo 属于特殊用途网卡,通常不要修改它)。

Network Configuration Files

CentOS7 和 CentOS6 的网卡命名方式有所不同,前者通常是ifcfg-enp0s3,后者是ifcfg-eth0(网卡名称后面的数字非固定,很多时候存在多个网卡接口)。


编辑网卡配置文件(如果有多个,配置其中一个就行)。以下是设置静态 IP 需要修改或添加的内容(文件里的其它原有参数,例如 TYPE、HWADDR 等不要删除)。

DEVICE=eth0                 # 网卡名称,保持默认
TYPE=Ethernet               # 网卡类型(以太网)
ONBOOT=yes                  # 启动时激活网络连接
BOOTPROTO=static            # 设置使用静态 IP
IPADDR=        # 设置 IP 地址
GATEWAY=         # 设置网关地址
NETMASK=       # 设置子网掩码
DNS1=                # 设置首选 DNS
DNS2=                # 设置备用 DNS
IPV6INIT=no                 # 禁用 IPv6
NM_CONTROLLED=no            # 禁用 NetworkManager 管理


设置后运行service network restart命令重启网络生效。之后用ifconfig检查 IP 绑定情况,其它计算机测试可以 ping 通 IP 就可以了。

网卡添加绑定多个 IP

如果要绑定多个 IP,可以添加多个 IPADDRx参数,尾数x是由 0 开始的连续整数。


若要设置各 IP 使用不同的子网掩码,相应添加NETMASKx参数即可(尾数x的数字 ID 与对应 IP 的一致)。注意网关通常不要设置多个,不然会影响网络访问。

如果要添加一个范围内的 IP 地址,请查看这篇文章介绍。


  1. #1

    order hydroxychloroquine online canada https://hydroxychloroquine.webbfenix.com/

  2. #2

    careprost eyelash enhancer https://carepro1st.com/

  3. #3

    clomid and liver problems in men https://salemeds24.wixsite.com/clomid

  4. #4

    what to expect from vidalista https://vidalista.mlsmalta.com/

  5. #5

    stromectol without prescription https://ivermectin.webbfenix.com/

  6. #6

    sildenafil 20 mg lowest price http://droga5.net/

  7. #7

    keflex interactions with other drugs https://keflex.webbfenix.com/

  8. #8

    hydroxychloroquine online mexico https://hydroxychloroquine.mlsmalta.com/

  9. #9

    free cialis 30 day trial http://www.lm360.us/

  10. #10

    ivermectin substitute over counter walgreens https://ivermectin.mlsmalta.com/

  11. #11

    reasons for priligy not working https://ddapoxetine.com/

  12. #12

    best antidepressant with tamoxifen https://tamoxifen.mrdgeography.com/

  13. #13

    taking too much vidalista https://vidalista40mg.mlsmalta.com/

  14. #14

    cost of tadalafil 5mg with insurance https://wisig.org/

  15. #15

    milf live cam

  16. #16

    loan me

  17. #17

    15 mg cialis

  18. #18

    fildena 100 mg online

  19. #19

    alaska loan

  20. #20

    buy provigil 100mg online

  21. #21

    tadalafil generic over the counter

  22. #22

    policybazaar car insurance

  23. #23

    teen cam chat

  24. #24

    wwwhamster adult chat

  25. #25

    where to buy generic cialis in usa

  26. #26

    personal loans for debt consolidation

  27. #27

    can i buy hydroxychloroquine in mexico https://hydroxychloroquinee.com/

  28. #28

    best home insurance companies

  29. #29

    hydroxychloroquine sulfate tablets 200mg https://hydroxychloroquine.grassfed.us/

  30. #30

    hydroxychloroquine sulfate tablets 200mg https://hydroxychloroquine.lm360.us/

  31. #31

    payday loans denver colorado

  32. #32

    how to get female viagra pills

  33. #33

    allied property and casualty insurance

  34. #34

    universal insurance

  35. #35

    tadalafil tab 10mg

  36. #36

    direct line home insurance

  37. #37

    mobile home insurance in florida

  38. #38

    The following time I read a blog, I hope that it doesnt disappoint me as much as this one. I imply, I know it was my choice to read, however I really thought youd have one thing interesting to say. All I hear is a bunch of whining about one thing that you would repair when you werent too busy searching for attention.
    goyard handbags http://www.goyardhandbag.us

  39. #39

    Your place is valueble for me. Thanks!?
    birkin bag http://www.hermesbirkinbags.us.com

  40. #40

    vidalista tadalafil 20 mg tablet https://vidalista.buszcentrum.com/

  41. #41

    I used to be very pleased to search out this web-site.I wanted to thanks for your time for this wonderful read!! I positively enjoying every little little bit of it and I’ve you bookmarked to take a look at new stuff you blog post.
    yeezy http://www.yeezy-boost350.us.com

  42. #42

    very good submit, i certainly love this web site, carry on it
    jordan 12 http://www.jordan12.us.com

  43. #43

    Your place is valueble for me. Thanks!?
    yeezy boost 350 http://www.yeezyboost350v2s.us

  44. #44

    This is the precise weblog for anyone who needs to find out about this topic. You notice a lot its virtually laborious to argue with you (not that I actually would want匟aHa). You definitely put a new spin on a subject thats been written about for years. Nice stuff, just great!
    lebron shoes http://www.lebronjames-shoes.us.com

  45. #45

    That is the fitting blog for anybody who desires to search out out about this topic. You realize a lot its nearly exhausting to argue with you (not that I actually would need匟aHa). You undoubtedly put a new spin on a subject thats been written about for years. Great stuff, simply nice!
    kyrie irving shoes http://www.kyrie7shoes.us

  46. #46

    Would you be desirous about exchanging hyperlinks?
    stone island http://www.stone-island.us.com

  47. #47

    I was very pleased to search out this net-site.I needed to thanks on your time for this wonderful learn!! I positively having fun with each little little bit of it and I have you bookmarked to check out new stuff you blog post.
    longchamp handbags http://www.longchampshandbags.us.org

  48. #48

    The next time I learn a weblog, I hope that it doesnt disappoint me as a lot as this one. I imply, I do know it was my option to read, but I actually thought youd have one thing interesting to say. All I hear is a bunch of whining about something that you possibly can fix when you werent too busy looking for attention.
    curry 6 http://www.curry6.net

  49. #49

    Would you be eager about exchanging links?
    moncler http://www.monclersoutletstore.com

  50. #50

    You should participate in a contest for among the finest blogs on the web. I’ll suggest this site!
    golden goose http://www.goldengooses.us

  51. #51

    A formidable share, I just given this onto a colleague who was doing a bit of evaluation on this. And he in actual fact bought me breakfast because I found it for him.. smile. So let me reword that: Thnx for the deal with! But yeah Thnkx for spending the time to debate this, I really feel strongly about it and love studying more on this topic. If attainable, as you become experience, would you thoughts updating your weblog with extra details? It is highly helpful for me. Large thumb up for this weblog publish!
    golden goose http://www.goldengoosessale.com


电邮地址用于 Gravatar 头像显示,不会被公开可见。