CentOS 配置网络连接(包括添加多个 IP 方法)
如果没有在 CentOS 安装过程中配置网络,之后需要手动修改网卡配置文件,设置静态 IP 地址和子网掩码(外网访问须同时设置网关和 DNS),相关信息可以从主机商处获取。下面介绍具体设置方法。
查看现有网卡信息
用ip address show
命令列出现有网卡及其 IP。如果输出内容太多,可用ip address show | less
分页查看。| 垂直线用 Shift + \ 组合键打出。less 用 Ctrl + F 和 Ctrl + B 前后翻页,q 退出。
也可以直接浏览查看网卡配置文件。
cd /etc/sysconfig/network-scripts && ls
示例输出,ifcfg-xxx
就是网卡配置文件(ifcfg-lo
属于特殊用途网卡,通常不要修改它)。
CentOS7 和 CentOS6 的网卡命名方式有所不同,前者通常是ifcfg-enp0s3
,后者是ifcfg-eth0
(网卡名称后面的数字非固定,很多时候存在多个网卡接口)。
配置启用网络连接
编辑网卡配置文件(如果有多个,配置其中一个就行)。以下是设置静态 IP 需要修改或添加的内容(文件里的其它原有参数,例如 TYPE、HWADDR 等不要删除)。
DEVICE=eth0 # 网卡名称,保持默认 TYPE=Ethernet # 网卡类型(以太网) ONBOOT=yes # 启动时激活网络连接 BOOTPROTO=static # 设置使用静态 IP IPADDR=192.168.1.100 # 设置 IP 地址 GATEWAY=192.168.1.1 # 设置网关地址 NETMASK=255.255.255.0 # 设置子网掩码 DNS1=1.1.1.1 # 设置首选 DNS DNS2=1.0.0.1 # 设置备用 DNS IPV6INIT=no # 禁用 IPv6 NM_CONTROLLED=no # 禁用 NetworkManager 管理
延伸:如需了解有关子网掩码、网关的作用可看网上这篇介绍,总结的通俗明了。
设置后运行service network restart
命令重启网络生效。之后用ifconfig
检查 IP 绑定情况,其它计算机测试可以 ping 通 IP 就可以了。
网卡添加绑定多个 IP
如果要绑定多个 IP,可以添加多个 IPADDRx
参数,尾数x
是由 0 开始的连续整数。
IPADDR0=192.168.1.101 IPADDR1=192.168.1.103 IPADDR2=192.168.1.105
若要设置各 IP 使用不同的子网掩码,相应添加NETMASKx
参数即可(尾数x
的数字 ID 与对应 IP 的一致)。注意网关通常不要设置多个,不然会影响网络访问。
如果要添加一个范围内的 IP 地址,请查看这篇文章介绍。
order hydroxychloroquine online canada https://hydroxychloroquine.webbfenix.com/
careprost eyelash enhancer https://carepro1st.com/
clomid and liver problems in men https://salemeds24.wixsite.com/clomid
what to expect from vidalista https://vidalista.mlsmalta.com/
stromectol without prescription https://ivermectin.webbfenix.com/
sildenafil 20 mg lowest price http://droga5.net/
keflex interactions with other drugs https://keflex.webbfenix.com/
hydroxychloroquine online mexico https://hydroxychloroquine.mlsmalta.com/
free cialis 30 day trial http://www.lm360.us/
ivermectin substitute over counter walgreens https://ivermectin.mlsmalta.com/
reasons for priligy not working https://ddapoxetine.com/
best antidepressant with tamoxifen https://tamoxifen.mrdgeography.com/
taking too much vidalista https://vidalista40mg.mlsmalta.com/
cost of tadalafil 5mg with insurance https://wisig.org/
milf live cam
loan me
15 mg cialis
fildena 100 mg online
alaska loan
buy provigil 100mg online
tadalafil generic over the counter
policybazaar car insurance
teen cam chat
wwwhamster adult chat
where to buy generic cialis in usa
personal loans for debt consolidation
can i buy hydroxychloroquine in mexico https://hydroxychloroquinee.com/
best home insurance companies
hydroxychloroquine sulfate tablets 200mg https://hydroxychloroquine.grassfed.us/
hydroxychloroquine sulfate tablets 200mg https://hydroxychloroquine.lm360.us/
payday loans denver colorado
how to get female viagra pills
allied property and casualty insurance
universal insurance
tadalafil tab 10mg
direct line home insurance
mobile home insurance in florida
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
Your place is valueble for me. Thanks!?
birkin bag http://www.hermesbirkinbags.us.com
vidalista tadalafil 20 mg tablet https://vidalista.buszcentrum.com/
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
very good submit, i certainly love this web site, carry on it
jordan 12 http://www.jordan12.us.com
Your place is valueble for me. Thanks!?
yeezy boost 350 http://www.yeezyboost350v2s.us
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
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
Would you be desirous about exchanging hyperlinks?
stone island http://www.stone-island.us.com
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
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
Would you be eager about exchanging links?
moncler http://www.monclersoutletstore.com
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
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