温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Linux中IP地址的配置

发布时间:2020-05-25 15:31:25 来源:亿速云 阅读:154 作者:鸽子 栏目:系统运维

一、设置Linux的IP地址
1.搞懂三种网卡模式:桥接、NAT、仅单机模式
2.选择NAT模式
1).vi /etc/sysconfig/network-script/ifcfg-eth0设置成自动获得IP地址。

DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp

2).执行ip a或者ifconfig获取得到的IP地址,并route -n获得路由信息,得到网关

DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.128.128
NETMASK=255.255.255.0
GATEWAY=192.168.128.2
DNS1=114.114.114.114

3).重启网卡service network restart

3.在ping www.baidu.com的时候发生Name or Service not know错误,经过排查
1).IP地址绑定主机名
cat /etc/hosts

192.168.128.128 Linux

2).cat /etc/sysconfig/network

NETWORKING=yes
HOSTNAME=Linux
GATEWAY=192.168.128.2
NOZEROCONF=yes

3).添加DNS服务器
nameserver 114.114.114.114
nameserver 114.114.114.115

4).关闭防火墙
以下是Cetos 7之前的版本:
临时关闭
service iptables stop
永久关闭
chkconfig iptables off
查看防火墙状态
chkconfig --list|grep iptables

以下是Centos 7之后的版本

systemctl stop firewalld

systemctl status firewalld

systemctl disable firewalld

systemctl enable firewalld

systemctl start firewalld

5).关闭安全策略
查看
getenforce
设置
setenforce
永久关闭
vi /etc/selinux/config
SELINUX=disabled

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI