Linux中IP地址的配置

一、设置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
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值