CentOS 添加绑定某个范围内的 IP 地址

Kevin 教程 1,984 次浏览 55条评论

CentOS 在同一网卡配置文件下添加多个 IP 可以用 IPADDRx 参数(x 是从 0 开始的连续整数)。也可以创建多个网卡配置文件,例如 ifcfg-eth0:x 这样以此类推,每个配置文件绑定 1 个 IP。

上述方法适合添加少量或不连续 IP 时使用,当要配置大量连续 IP 则可以用另一个方法,更加简单。

CentOS 添加某个 CIDR 范围 IP 地址

1. 进入网卡配置文件目录,找到当前配置外网连接的主网卡。假设网卡名为 ifcfg-eth1。

cd /etc/sysconfig/network-scripts && vi ifcfg-eth1

将文件内的 NM_CONTROLLED 参数设为 no(没有则添加该参数),使之摆脱可能受到 NetworkManager 程序的控制影响。

NM_CONTROLLED=no

2. 创建添加 IP 范围的配置文件,命名方式在网卡名称后加-range0。若要添加多个 IP 范围,则相应创建多个 range 配置文件,例如 range0,range1,range2 这样。

vi ifcfg-eth1-range0

配置文件内容参数如下(不必添加 DEVICE、ONBOOT、GATEWAY 等参数)。

IPADDR_START=1.1.1.1       # IP 范围内首个可用 IP
IPADDR_END=1.1.1.30        # IP 范围内最后可用 IP
NETMASK=255.255.255.224    # 子网掩码,也可以用 PREFIX=27 参数设置,是同样作用
CLONENUM_START=0           # 设置网卡别名的起始数,0 表示从 eth1:0 开始添加 IP
                           # 假设添加 IP 范围有 30 个 IP,设置后会自动生成 eth1:0 - eth1:29
                           # 正确方法是设置具体值前,先用 ifconfig 查询当前网卡别名使用情况
                           # 假设已存在 eth1:0,则值必须向推后,使用 1 或其它没有被使用的 ID
NO_ALIASROUTING=yes        # 设置数据包不走网卡别名,而是通过 eth1 网卡,可提高路由响应速度

示例添加 1.1.1.1/27 范围 IP,计算可用 IP 范围和子网掩码可以用这个在线工具

附不同 IP 范围所对应的子网掩码
前缀大小 子网掩码 可用 IP 数 所能划分的子网数 划分后的总可用 IP 数
/24 255.255.255.0 254 1 254
/25 255.255.255.128 126 2 252
/26 255.255.255.192 62 4 248
/27 255.255.255.224 30 8 240
/28 255.255.255.240 14 16 224
/29 255.255.255.248 6 32 192
/30 255.255.255.252 2 64 128
/31 255.255.255.254 2 128 256
延伸:IP 段分类有 A、B、C 三种。在 IP 地址的四段号码中,前 1 段网络号后 3 段本地号为 A 类,前 2 段网络号后 2 段本地号为 B 类,前 3 段网络号后 1 段本地号为 C 类。通常普通用户能拥有 IP 段是 C 类

3. 正确完成上面设置后,service network restart重启网络生效。在这过程会自动逐个添加 IP,耐心等待其完成,之后随机 ping 几个 IP 检查是否绑定成功。

本文方法同样适用其他 RHEL 系操作系统,例如 Fedora、ClearOS等。

如果不想麻烦手动配置,网上看到有个自动配置脚本(未测试),有兴趣的可以试试。

评论列表

  1. #1

    how long for careprost to work https://carepro1st.com/

  2. #2

    dapoxetine for women’s libido https://salemeds24.wixsite.com/dapoxetine

  3. #3

    hydroxychloroquine 200mg side effects https://hydroxychloroquine.webbfenix.com/

  4. #4

    prices for ivermectin https://ivermectin.mlsmalta.com/

  5. #5

    hydroxychloroquine coronavirus dosage https://hydroxychloroquine.mlsmalta.com/

  6. #6

    mobile pharmacy generic ivermectin https://ivermectin.webbfenix.com/

  7. #7

    cialis 20 mg generic http://www.lm360.us/

  8. #8

    keflex for dogs ear infection https://keflex.webbfenix.com/

  9. #9

    sildenafil tadalafil dosage equivalent http://droga5.net/

  10. #10

    hydroxychloroquine for sale amazon https://hhydroxychloroquine.com/

  11. #11

    vietnamese vidalista ingredients https://vidalista.mlsmalta.com/

  12. #12

    viagra versus vidalista results https://vidalista40mg.mlsmalta.com/

  13. #13

    buy cialis viagra https://wisig.org/

  14. #14

    Over The Counter Cialis Easettenex buy cialis online with prescription Alicky Diflucan Online Uk

  15. #15

    is ventolin a generic for albuterol sulfate https://amstyles.com/

  16. #16

    is generic dapoxetine available yet https://ddapoxetine.com/

  17. #17

    active ingredients in hydroxychloroquine https://hydroxychloroquinee.com/

  18. #18

    tadalafil side effects from mayo clinic https://tadalafili.com/

  19. #19

    hydroxychloroquine and zithromax https://hydroxychloroquine.lm360.us/

  20. #20

    free printable coupons for medications https://buymeds.mlsmalta.com/

  21. #21

    free printable coupons for medications https://medpills.bee-rich.com/

  22. #22

    best time to take cialis https://tadalafil365.online/

  23. #23

    best time to take cialis https://atadalafil.online/

  24. #24

    sildenafil dapoxetine tablets https://dapoxetine.confrancisyalgomas.com/

  25. #25

    cost of aralen without insurance https://hydroxychloroquine.mymvrc.org/

  26. #26

    vidalista 20 rxtoed http://viidalista.co/

  27. #27

    viagra prescription online canada https://zsildenafil.com/

  28. #28

    cialis without a doctor prescription http://ciialis.co/

  29. #29

    generic tadalafil usa https://tadalafil.cleckleyfloors.com/

  30. #30

    aurogra 100mg price walgreens https://aurogra.buszcentrum.com/

  31. #31

    hydroxychloroquine purchase online https://hydroxychloroquine4u.com/

  32. #32

    cvs prescription cost estimator https://buymeds.mlsmalta.com/

  33. #33

    cvs prescription cost estimator https://edmeds.buszcentrum.com/

  34. #34

    cialis pills for men http://tadalafila.online/

  35. #35

    low cost cialis 20mg http://cialis.audiovideoninja.com/

  36. #36

    low cost cialis 20mg https://cialis.bee-rich.com/

  37. #37

    can cialis cause back pain https://cialis.adicbc.com/

  38. #38

    can cialis cause back pain https://cialis.grassfed.us/

  39. #39

    buy cialis online https://cialzi.com/

  40. #40

    It’s truly very complicated in this busy life to listen news on TV, thus I simply use the web for that purpose,
    and take the most recent news. http://antiibioticsland.com/Augmentin.htm

  41. #41

    Great delivery. Outstanding arguments. Keep up the amazing work. http://cialis.anafassia.com/tadalafil

  42. #42

    An intriguing discussion is worth comment.
    I think that you ought to write more on this topic, it
    may not be a taboo subject but generally people don’t speak about these topics.
    To the next! Kind regards!! https://hydroxychloroquineg.grassfed.us/

  43. #43

    What’s Taking place i’m new to this, I stumbled upon this I have found It positively useful and it has aided me out loads. I am hoping to contribute & aid other customers like its aided me. Great job.

    http://www.vreyrolinomit.com/

  44. #44

    I am regular reader, how are you everybody?
    This paragraph posted at this web site is really nice. http://herreramedical.org/sildenafil

  45. #45

    Heya! I’m at work surfing around your blog from my new apple iphone!
    Just wanted to say I love reading your blog and look forward to all your posts!
    Carry on the outstanding work! http://www.deinformedvoters.org/sildenafil-price

  46. #46

    I’m really loving the theme/design of your blog.
    Do you ever run into any internet browser compatibility problems?
    A number of my blog visitors have complained about my blog not operating correctly in Explorer
    but looks great in Opera. Do you have any recommendations to help fix this problem? http://www.deinformedvoters.org/aurogra-online

  47. #47

    buy hydroxychloroquine online https://hydroxychloroquinex.com/

  48. #48

    Thank you for sharing superb informations. Your website is very cool. I am impressed by the details that you?¦ve on this blog. It reveals how nicely you understand this subject. Bookmarked this website page, will come back for more articles. You, my pal, ROCK! I found just the info I already searched everywhere and simply couldn’t come across. What an ideal site.

    http://www.zortilonrel.com/

  49. #49

    My partner and I stumbled over here coming from a different page and thought I may
    as well check things out. I like what I see so now i’m following you.
    Look forward to finding out about your web page for a second time. https://cialis.buszcentrum.com/tadalafil

  50. #50

    I have recently started a site, the info you offer on this website has helped me tremendously. Thank you for all of your time & work. “Money is power, freedom, a cushion, the root of al evil, the sum of all blessings.” by Carl Sandburg.

    http://www.vreyrolinomit.com/

  51. #51

    I’m more than happy to find this great site.
    I wanted to thank you for your time due to this wonderful read!!
    I definitely liked every little bit of it and i
    also have you saved as a favorite to see
    new information in your site. https://cialis360.jueriy.com/tadalafil

  52. #52

    Have you ever heard of second life (sl for short). It is basically a game where you can do anything you want. SL is literally my second life (pun intended lol). If you want to see more you can see these second life articles and blogs

    wiki.jokaydia.com/index.php?title=LiteratureCompositionCreative_Writing&direction=next&oldid=438&printable=yes&printable=yes

  53. #53

    Have you ever heard of second life (sl for short). It is basically a video game where you can do anything you want. Second life is literally my second life (pun intended lol). If you would like to see more you can see these sl articles and blogs

    http://www.secondlifepagina.nl/

  54. #54

    edu

  55. #55

    Appreciating the dedication you put into your website and in depth information you present.

    It’s nice to come across a blog every once in a while that isn’t the same
    out of date rehashed material. Excellent read! I’ve bookmarked your site
    and I’m adding your RSS feeds to my Google account. https://hydroxychloroquinec.confrancisyalgomas.com/

发表评论

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