换了一个同事的vpn的网络,同事的机子变成了我路由器控制下的局域网,然后同事机子上不去网了。
怎么弄都显示eth0 不认识,于是命令行设置下。
ifconfig 设置 接口 ip 掩码
ifconfig eth0 192.168.1.111 255.255.255.0
route 设置网关
route add default gw 192.168.1.1
dns在 /etc/resolv.conf中设置。
zhangbin@Ubuntu32:~$ ifconfig --help
Usage:
ifconfig [-a] [-v] [-s] <interface> [[<AF>] <address>]
[add <address>[/<prefixlen>]]
[del <address>[/<prefixlen>]]
[[-]broadcast [<address>]] [[-]pointopoint [<address>]]
[netmask <address>] [dstaddr <address>] [tunnel <address>]
[outfill <NN>] [keepalive <NN>]
[hw <HW> <address>] [metric <NN>] [mtu <NN>]
[[-]trailers] [[-]arp] [[-]allmulti]
[multicast] [[-]promisc]
[mem_start <NN>] [io_addr <NN>] [irq <NN>] [media <type>]
[txqueuelen <NN>]
[[-]dynamic]
[up|down] ...
<HW>=Hardware Type.
List of possible hardware types:
loop (Local Loopback) slip (Serial Line IP) cslip (VJ Serial Line IP)
slip6 (6-bit Serial Line IP) cslip6 (VJ 6-bit Serial Line IP) adaptive (Adaptive Serial Line IP)
strip (Metricom Starmode IP) ash (Ash) ether (Ethernet)
tr (16/4 Mbps Token Ring) tr (16/4 Mbps Token Ring (New)) ax25 (AMPR AX.25)
netrom (AMPR NET/ROM) rose (AMPR ROSE) tunnel (IPIP Tunnel)
ppp (Point-to-Point Protocol) hdlc ((Cisco)-HDLC) lapb (LAPB)
arcnet (ARCnet) dlci (Frame Relay DLCI) frad (Frame Relay Access Device)
sit (IPv6-in-IPv4) fddi (Fiber Distributed Data Interface) hippi (HIPPI)
irda (IrLAP) ec (Econet) x25 (generic X.25)
eui64 (Generic EUI-64)
<AF>=Address family. Default: inet
List of possible address families:
unix (UNIX Domain) inet (DARPA Internet) inet6 (IPv6)
ax25 (AMPR AX.25) netrom (AMPR NET/ROM) rose (AMPR ROSE)
ipx (Novell IPX) ddp (Appletalk DDP) ec (Econet)
ash (Ash) x25 (CCITT X.25)
zhangbin@Ubuntu32:~$
zhangbin@Ubuntu32:~$ route --help
Usage: route [-nNvee] [-FC] [<AF>] List kernel routing tables
route [-v] [-FC] {add|del|flush} ... Modify routing table for AF.
route {-h|--help} [<AF>] Detailed usage syntax for specified AF.
route {-V|--version} Display version/author and exit.
-v, --verbose be verbose
-n, --numeric don't resolve names
-e, --extend display other/more information
-F, --fib display Forwarding Information Base (default)
-C, --cache display routing cache instead of FIB
<AF>=Use '-A <af>' or '--<af>'; default: inet
List of possible address families (which support routing):
inet (DARPA Internet) inet6 (IPv6) ax25 (AMPR AX.25)
netrom (AMPR NET/ROM) ipx (Novell IPX) ddp (Appletalk DDP)
x25 (CCITT X.25)
zhangbin@Ubuntu32:~$
================================
参考 http://blog.youkuaiyun.com/happyjiang2009/article/details/5730017
如果主机操作系统就是Ubuntu,请直接参照下文进行设置
转载内容如下:
1. 检验是否可以连通,就使用ping命令ping 网关
开始的时候总是现实unreachable
2. 设置IP
sudo ifconfig eth0 133.133.133.190 netmask 255.255.255.0
这样就算设置好了网卡eth0的IP地址和子网掩码
3. 设置网关 sudo route add default gw 133.133.133.40
4. ping 网关就可以ping通了
5. 设置DNS 修改/etc/resolv.conf,在其中加入
nameserver DNS的地址1
nameserver DNS的地址2
完成。
这样设置之后,下次开机时候似乎IP又会发生变化。
永久修改Ubuntu LINUX IP
一、使用命令设置ubuntu的ip地址
1. 设置IP sudo ifconfig eth0 203.171.239.155 netmask 255.255.255.224 这样就算设置好了网卡eth0的IP地址和子网掩码
2. 设置网关 sudo route add default gw 203.171.239.129
3. 设置DNS 修改/etc/resolv.conf,在其中加入 nameserver DNS的地址1 nameserver DNS的地址2 完成。 不过,这样设置之后,下次开机时候似乎IP又不存在了。
二、直接修改系统配置文件 ubuntu的网络配置文件是:/etc/network/interfaces 打开后里面可设置DHCP或手动设置静态ip。前面auto eth0,让网卡开机自动挂载.
1. 以DHCP方式配置网卡编辑文件,切换到/etc/network/interfaces: 指定如下命令,sudo vi /etc/network/interfaces
并用下面的行来替换有关eth0的行:
# The primary network interface - use DHCP to find our address
auto eth0 iface
eth0 inet dhcp
用下面的命令使网络设置生效: sudo /etc/init.d/networking restart
也可以在命令行下直接输入下面的命令来获取地址 sudo dhclient eth0
2. 为网卡配置静态IP地址编辑文件
/etc/network/interfaces: sudo vi /etc/network/interfaces
并用下面的行来替换有关eth0的行:
# The primary network interface
auto eth0
iface eth0 inet static
address 203.171.239.155
gateway 203.171.239.129
netmask 255.255.255.224
#network 203.171.239.128 #broadcast 192.168.3.159
将上面的ip地址等信息换成你自己就可以了.用下面的命令使网络设置生效: sudo /etc/init.d/networking restart
3. 设定第二个IP地址(虚拟IP地址) 编辑文件
/etc/network/interfaces: sudo vi /etc/network/interfaces
在该文件中添加如下的行:
auto eth0:1 iface eth0:1 inet static address 192.168.1.155 netmask 255.255.255.0 work x.x.x.x broadcast x.x.x.x gateway x.x.x.x 根据你的情况填上所有诸如address,netmask,network,broadcast和gateways等信息. 用下面的命令使网络设置生效: sudo /etc/init.d/networking restart
4. 设置主机名称(hostname) 使用下面的命令来查看当前主机的主机名称: sudo /bin/hostname 使用下面的命令来设置当前主机的主机名称: sudo /bin/hostname newname 系统启动时,它会从/etc/hostname来读取主机的名称. 5. 配置DNS 首先,你可以在/etc/hosts中加入一些主机名称和这些主机名称对应的IP地址,这是简单使用本机的静态查询. 要访问DNS 服务器来进行查询,需要设置/etc/resolv.conf文件. 假设DNS服务器的IP地址是203.171.230.6 resolv.conf文件的内容应为: search test.com nameserver 203.171.230.6 重启网络:/etc/init.d/networking restart