• Linux ->> UBuntu 14.04 LTE下设置静态IP地址


    UBuntu 14.04 LTE设置IP地址和一些服务器版本的Linux还不太一样。以Centos 7.0为例,网卡IP地址的配置文件应该是/etc/sysconfig/network-scripts/ifcfg-eth0

    首先UBuntu 14.04 LTE下面IP地址的配置文件是/etc/network/interfaces。

    jerry@ubuntu:/etc/network$ cat /etc/network/interfaces
    # interfaces(5) file used by ifup(8) and ifdown(8)
    auto lo
    iface lo inet loopback       
    
    auto eth0
    iface eth0 inet static
    address 192.168.2.100
    gateway 192.168.2.2
    netmask 255.255.255.0
    network 192.168.2.0
    broadcast 192.168.2.255
    dns-nameservers 8.8.8.8 
    jerry@ubuntu:/etc/network$ 

    把地址配好后用ifdown eth0后跟上ifup eth0重启网卡让前面的配置生效

    jerry@ubuntu:/etc/network$ sudo ifdown eth0 
    jerry@ubuntu:/etc/network$ sudo ifup eth0 
    jerry@ubuntu:/etc/network$ ifconfig
    eth0      Link encap:Ethernet  HWaddr 00:0c:29:e7:e6:57  
              inet addr:192.168.2.100  Bcast:192.168.2.255  Mask:255.255.255.0
              inet6 addr: fe80::20c:29ff:fee7:e657/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:275 errors:0 dropped:0 overruns:0 frame:0
              TX packets:374 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:31264 (31.2 KB)  TX bytes:46453 (46.4 KB)
    
    lo        Link encap:Local Loopback  
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:65536  Metric:1
              RX packets:47566 errors:0 dropped:0 overruns:0 frame:0
              TX packets:47566 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0 
              RX bytes:8344572 (8.3 MB)  TX bytes:8344572 (8.3 MB)
    
    jerry@ubuntu:/etc/network$ ping www.baidu.com
    PING www.a.shifen.com (61.135.169.121) 56(84) bytes of data.
    64 bytes from 61.135.169.121: icmp_seq=1 ttl=128 time=102 ms
    64 bytes from 61.135.169.121: icmp_seq=2 ttl=128 time=54.9 ms
    ^C
    --- www.a.shifen.com ping statistics ---
    3 packets transmitted, 2 received, 33% packet loss, time 6396ms
    rtt min/avg/max/mdev = 54.940/78.678/102.417/23.740 ms

    有时你在一台刚刚安装好的Ubuntu机器上运行ifdown eth0命令可能会出现ifdown: interface eth0 not configured这样的错误提示,原因是ifdown和ifup是依据/run/network/ifstate里的内容来知道有哪些网络接口。cat一下有没有eth0,没有就添加eth0=eth0到文件的尾端。然后再运行下命令就解决了。

    jerry@ubuntu:/etc/network$ sudo ifdown eth0 
    ifdown: interface eth0 not configured
    jerry@ubuntu:/etc/network$ ifconfig
    eth0      Link encap:Ethernet  HWaddr 00:0c:29:96:f1:cb  
              inet addr:192.168.2.129  Bcast:192.168.2.255  Mask:255.255.255.0
              inet6 addr: fe80::20c:29ff:fe96:f1cb/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:5892 errors:0 dropped:0 overruns:0 frame:0
              TX packets:2767 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:7515173 (7.5 MB)  TX bytes:232642 (232.6 KB)
    
    lo        Link encap:Local Loopback  
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:65536  Metric:1
              RX packets:191 errors:0 dropped:0 overruns:0 frame:0
              TX packets:191 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0 
              RX bytes:16954 (16.9 KB)  TX bytes:16954 (16.9 KB)
    
    jerry@ubuntu:/etc/network$ ping 192.168.2.2
    PING 192.168.2.2 (192.168.2.2) 56(84) bytes of data.
    64 bytes from 192.168.2.2: icmp_seq=1 ttl=128 time=0.328 ms
    64 bytes from 192.168.2.2: icmp_seq=2 ttl=128 time=0.153 ms
    64 bytes from 192.168.2.2: icmp_seq=3 ttl=128 time=0.285 ms
    ^C
    --- 192.168.2.2 ping statistics ---
    3 packets transmitted, 3 received, 0% packet loss, time 1998ms
    rtt min/avg/max/mdev = 0.153/0.255/0.328/0.075 ms
    jerry@ubuntu:/etc/network$ cd /run/network/
    jerry@ubuntu:/run/network$ ls
    ifstate  ifup.eth0  ifup.lo  static-network-up-emitted
    jerry@ubuntu:/run/network$ cat if
    ifstate    ifup.eth0  ifup.lo    
    jerry@ubuntu:/run/network$ cat ifstate 
    lo=lo
    jerry@ubuntu:/run/network$ vim ifstate 
    jerry@ubuntu:/run/network$ sudo vim ifstate 
    jerry@ubuntu:/run/network$ sudo ifdown eth0 
    RTNETLINK answers: No such process
    jerry@ubuntu:/run/network$ sudo ifup eth0 
    jerry@ubuntu:/run/network$ ifconfig
    eth0      Link encap:Ethernet  HWaddr 00:0c:29:96:f1:cb  
              inet addr:192.168.2.129  Bcast:192.168.2.255  Mask:255.255.255.0
              inet6 addr: fe80::20c:29ff:fe96:f1cb/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:5912 errors:0 dropped:0 overruns:0 frame:0
              TX packets:2823 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:7517625 (7.5 MB)  TX bytes:240569 (240.5 KB)
    
    lo        Link encap:Local Loopback  
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:65536  Metric:1
              RX packets:279 errors:0 dropped:0 overruns:0 frame:0
              TX packets:279 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0 
              RX bytes:24074 (24.0 KB)  TX bytes:24074 (24.0 KB)
    
    jerry@ubuntu:/run/network$ ifconfig
    eth0      Link encap:Ethernet  HWaddr 00:0c:29:96:f1:cb  
              inet addr:192.168.2.129  Bcast:192.168.2.255  Mask:255.255.255.0
              inet6 addr: fe80::20c:29ff:fe96:f1cb/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:5914 errors:0 dropped:0 overruns:0 frame:0
              TX packets:2832 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:7517805 (7.5 MB)  TX bytes:242116 (242.1 KB)
    
    lo        Link encap:Local Loopback  
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:65536  Metric:1
              RX packets:279 errors:0 dropped:0 overruns:0 frame:0
              TX packets:279 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0 
              RX bytes:24074 (24.0 KB)  TX bytes:24074 (24.0 KB)
    
    jerry@ubuntu:/run/network$ sudo ifdown eth0 
    jerry@ubuntu:/run/network$ sudo ifup eth0 
    jerry@ubuntu:/run/network$ ifconfig 
    eth0      Link encap:Ethernet  HWaddr 00:0c:29:96:f1:cb  
              inet addr:192.168.2.110  Bcast:192.168.2.255  Mask:255.255.255.0
              inet6 addr: fe80::20c:29ff:fe96:f1cb/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:5936 errors:0 dropped:0 overruns:0 frame:0
              TX packets:2895 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:7520193 (7.5 MB)  TX bytes:250378 (250.3 KB)
    
    lo        Link encap:Local Loopback  
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:65536  Metric:1
              RX packets:285 errors:0 dropped:0 overruns:0 frame:0
              TX packets:285 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0 
              RX bytes:24592 (24.5 KB)  TX bytes:24592 (24.5 KB)
    
    jerry@ubuntu:/run/network$ 

    下面是Ubuntu的官方文档专门讲网络设置的

    网络配置

  • 相关阅读:
    迅雷极速版 2020年 防止升级方法
    微PE WEPEMENU.INI CDLINUX BEINI 启动菜单
    tcping 0.39
    海康威视楼宇可视对讲解码器拨码规则计算器-安卓版
    博客园-文字互动插件
    WSL-Ubuntu 安装Xubuntu-Desktop 记录
    html css的冷门相关基础知识整理
    git hub 的冲突解决方案
    css实现垂直居中的方式
    js中BOM相关知识
  • 原文地址:https://www.cnblogs.com/jenrrychen/p/5079395.html
Copyright © 2020-2023  润新知