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() file used by ifup() and ifdown()
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 :0c::e7:e6:
inet addr:192.168.2.100 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fee7:e657/ Scope:Link
UP BROADCAST RUNNING MULTICAST MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (31.2 KB) TX bytes: (46.4 KB) lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::/ Scope:Host
UP LOOPBACK RUNNING MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (8.3 MB) TX bytes: (8.3 MB) jerry@ubuntu:/etc/network$ ping www.baidu.com
PING www.a.shifen.com (61.135.169.121) () bytes of data.
bytes from 61.135.169.121: icmp_seq= ttl= time= ms
bytes from 61.135.169.121: icmp_seq= ttl= time=54.9 ms
^C
--- www.a.shifen.com ping statistics ---
packets transmitted, received, % 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 :0c:::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/ Scope:Link
UP BROADCAST RUNNING MULTICAST MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (7.5 MB) TX bytes: (232.6 KB) lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::/ Scope:Host
UP LOOPBACK RUNNING MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (16.9 KB) TX bytes: (16.9 KB) jerry@ubuntu:/etc/network$ ping 192.168.2.2
PING 192.168.2.2 (192.168.2.2) () bytes of data.
bytes from 192.168.2.2: icmp_seq= ttl= time=0.328 ms
bytes from 192.168.2.2: icmp_seq= ttl= time=0.153 ms
bytes from 192.168.2.2: icmp_seq= ttl= time=0.285 ms
^C
--- 192.168.2.2 ping statistics ---
packets transmitted, received, % 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 :0c:::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/ Scope:Link
UP BROADCAST RUNNING MULTICAST MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (7.5 MB) TX bytes: (240.5 KB) lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::/ Scope:Host
UP LOOPBACK RUNNING MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (24.0 KB) TX bytes: (24.0 KB) jerry@ubuntu:/run/network$ ifconfig
eth0 Link encap:Ethernet HWaddr :0c:::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/ Scope:Link
UP BROADCAST RUNNING MULTICAST MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (7.5 MB) TX bytes: (242.1 KB) lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::/ Scope:Host
UP LOOPBACK RUNNING MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (24.0 KB) TX bytes: (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 :0c:::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/ Scope:Link
UP BROADCAST RUNNING MULTICAST MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (7.5 MB) TX bytes: (250.3 KB) lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::/ Scope:Host
UP LOOPBACK RUNNING MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (24.5 KB) TX bytes: (24.5 KB) jerry@ubuntu:/run/network$

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

网络配置

Linux ->> UBuntu 14.04 LTE下设置静态IP地址的更多相关文章

  1. Linux ->> UBuntu 14.04 LTE下主机名称和IP地址解析

    UBuntu 14.04 LTE下主机名称和IP地址解析一些相关的配置文件: /etc/hosts: 主机文件.手工配置IP地址和主机名称间的映射.格式为每行一条映射条项: <machine_n ...

  2. Linux ->> UBuntu 14.04 LTE下安装Hadoop 1.2.1(伪分布模式)

    Hadoop的运行模式可分为单机模式.伪分布模式和分布模式. 首先无论哪种模式都需要安装JDK的,这一步之前的随笔Ubuntu 14.04 LTE下安装JDK 1.8中已经做了.这里就不多说了. 其次 ...

  3. Linux ->> UBuntu 14.04 LTE下安装Hadoop 1.2.1(集群分布式模式)

    安装步骤: 1) JDK -- Hadoop是用Java写的,不安装Java虚拟机怎么运行Hadoop的程序: 2)创建专门用于运行和执行hadoop任务(比如map和reduce任务)的linux用 ...

  4. Linux ->> Ubuntu 14.04 LTE下配置SSH免密码登录

    首先用apt-get命令安装SSH jerry@ubuntu:~$ sudo apt-get install ssh [sudo] password for jerry: Reading packag ...

  5. Linux ->> Ubuntu 14.04 LTE下安装JDK 1.8

    先到Oracle官网的下载中心下载JDK8的tar包到本地. 下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-dow ...

  6. 虚拟机 - NAT模式下设置静态 IP 地址

    背景 如果不给虚拟机设置静态 IP 地址的话,每次重启机器都会自动分配一个新的 IP 如果有多台虚拟机的话,也会动态获取 IP 动态IP的话,每次 设置静态 IP 的步骤 查看本机 IP 和网关 cm ...

  7. Git使用:Linux(Ubuntu 14.04 x64)下安装Git并配置连接GitHub

    github是一个非常好的网络代码托管仓库,知晓许久,但是一直没有用起来,最近才开始使用git管理自己的文档和代码. Git是非常强大的版本管理工具,今天就告诉大家,如何在Linux下安装GIt,并且 ...

  8. Linux Ubuntu 14.04 LTS下VirtualBox连接USB

    1.环境 主机:Ubuntu 14.04 LTS 虚拟机:Windows 7 专业版本 VirtualBox: 图形用户界面版本 5.1.8 r111374 (Qt5.6.1) 2.在主机上给Virt ...

  9. Centos 下设置静态ip地址

       今天小编遇到了需要设置centos(6.4) 下静态ip地址,下面把详细步骤记录下来. 1> 首先打开这个 vi /etc/sysconfig/network-scripts/ifcfg- ...

随机推荐

  1. element-ui日期组件DatePicker选择日期范围赋值编辑问题

    最近在项目中使用element-UI的日期范围组件时遇到一个问题,相信很多人也做过这种场景,一个录入页面也同时是编辑页面,编辑的时候就需要先赋值.但是我给date组件赋值后,确无法操作了,change ...

  2. Monkey基本使用(转载)

    什么是 Monkey Monkey 是一个 Android 自动化测试小工具.主要用于Android 的压力测试, 主要目的就是为了测试app 是否会Crash. Monkey 特点 顾名思义,Mon ...

  3. google +ubuntu16.04

    1.在终端中输入以下命令 sudo wget https://repo.fdzh.org/chrome/google-chrome.list -P /etc/apt/sources.list.d/ 2 ...

  4. Python与C相互调用、编译

    因为最近学习Boost::python的缘故,想尝试下不同语言之间的相互编译. 参考资料:http://blog.csdn.net/joliny/article/details/2457197. 很吃 ...

  5. Junit参数化

    数据驱动测试:测试代码要与测试数据分离 哎~~学习时发现一个问题,写完了测试文件,右击文件时没有run as ->junit test的选项,找了好半天,终于知道了原因,是方法前没有加stati ...

  6. Zookeeper概念学习系列之paxos协议

    不多说,直接上干货! 前言 一种最终一致的算法,paxos算法. paxos算法是由大牛lamport发明的,关于paxos算法有很多趣事.比如lamport论文最初由故事描述来引入算法,以至于那班习 ...

  7. jsp模板添加URL定位语句

    html的head头中加入以下语句,方便url链接诶编写定位 <base href="${pageContext.request.scheme}://${pageContext.req ...

  8. orcale 之 SQL 数据查询

    从数据库中检索行,并允许从一个或多个表中选择一个或多个行或列.虽然 SELECT 语句的完整语法较复杂,但是其主要的子句可归纳如下: SELECT select_list [ INTO new_tab ...

  9. 从C语言的整数取值范围说开去

    在ILP32中, char, short, int, long, long long, pointer分别占1, 2, 4, 4, 8, 4个字节,在 LP64中, char, short, int, ...

  10. Signal Handling--ref

    http://www.chemie.fu-berlin.de/chemnet/use/info/libc/libc_21.html A signal is a software interrupt d ...