• Ubuntu网卡配置


    Ubuntu网卡配置

    临时配置

    使用ifconfig可以临时配置网卡的ip,机器重启后将失效

    配置网卡eth0的ip为192.168.0.199,子网掩码255.255.255.0(24)
    # ifconfig eth0 192.168.0.199/24
    
    启动网卡
    # ifconfig eth0 up 或者 ifup eth0
    
    关闭网卡
    #ifconfig eth0 down 或者 ifdown eth0
    

    永久生效

    让网卡的配置永久生效需要修改配置文件,网卡配置文件为/etc/network/interfaces

    配置静态IP

    为eth0设置静态IP, 编辑配置文件/etc/network/interfaces

    对eth0进行配置,加入以下内容
    auto eth0                            开机自启动网卡
    iface eth0 inet static               使用静态IP
    		address 192.168.1.10          IP地址
            netmask 255.255.255.0		 掩码
            gateway 192.168.1.1
            network 192.168.1.0	         所在网络,可以不设置
            broadcast 192.168.1.255      广播域,可以不设置
            dns-nameservers 8.8.8.8 114.114.114.114    配置DNS服务器,可以多配置几个
    

    为eth0设置动态IP

    auto eth0
    iface eth0 inet dhcp
    

    我们还可以配置虚拟网卡eth0:0

    # eth0是真实的物理网卡
    auto eth0                           
    iface eth0 inet static               
    		address 192.168.1.10         
            netmask 255.255.255.0
            gateway 192.168.1.1
            network 192.168.1.0
            broadcast 192.168.1.255
            
    # eth0:0是在物理网卡上虚拟出的网络
    auto eth0:0 
    iface eth0:0 inet static
    		address 192.168.1.11
            netmask 255.255.255.0		 
            gateway 192.168.1.1
            network 192.168.1.0	         
            broadcast 192.168.1.255
    

    重启生效

    让上面的配置生效,需要重启网络

    service networking restart
    

    有时候上面的命令执行会出现问题,那么需要重启网卡

    ifdown eth0
    ifup eth0
    
  • 相关阅读:
    数组的一些经典案例(循环)(max=score[0])(冒泡)(flag标志)(杨辉三角)
    冒泡排序
    C语言之数组
    循环结构的一些案例:倒等腰三角形、菱形、暴力破解
    break和contine关键字
    循环嵌套(打印*** ***)
    循环的经典案例(李白买酒)
    C语言循环结构-while/do...while/for--逢3过,阶乘,九九乘法表
    WordPress部署踩坑记
    Symbol
  • 原文地址:https://www.cnblogs.com/xidongyu/p/7816802.html
Copyright © 2020-2023  润新知