linux服务器配置ip?Linux用什么命令设置IP地址啊
各位老铁们,大家好,今天由我来为大家分享linux服务器配置ip,以及Linux用什么命令设置IP地址啊的相关问题知识,希望对大家有所帮助。如果可以帮助到大家,还望关注收藏下本站,您的支持是我们最大的动力,谢谢大家了哈,下面我们开始吧!
linux配置ip地址
linux配置ip地址的方法如下:
工具:联想Y7000P、Windows10。
1、以根用户登录系统,然后使用lspci| grep Ethernet命令检查计算机上的以太网卡设备是否被内核检测到。在默认的情况下,只有root也就是根用户才有权限进行网络配置。红框内就是检测到的网卡信息。
2、使用ifconfig命令查看系统已经识别并已激活的网络接口。如果没有找到可以用“ifconfig-a”命令找到所有已识别包括未激活的网络接口,然后使用ifconfig网卡名up激活。可以看出我的CentOS6.4系统上有一块已激活的eth0网卡,下面就对这块网卡进行设置使它能够发挥作用。
3、这里我首先为大家演示如何临时指定IP地址。在命令行输入“ifconfig网卡名IP地址netmask子网掩码”就可以临时指定网卡的IP地址,但重启后失效。相对于上一张图,我的IP临时设置已经生效。
4、为大家演示如何永久改变IP地址。第一步用“vi/etc/sysconfig/network-scripts/ifcfg-eth0”编辑网卡eth0的配置文件。dhcp自动获取IP地址,那么IPADDR、NETMASK和GATWAY都可以不写。
5、使用service network restart命令重新启动network服务,使配置文件生效。四个状态都必须是OK,否则说明设置有问题,需要重新修改设置。
6、再次使用ifconfig命令查看网卡参数,可以看出IP地址修改成功,并且会一直保留。
Linux用什么命令设置IP地址啊
Linux命令行下配置IP地址的几种配置方法:
即时生效(重启后失效):
ifconfig eth0 192.168.1.102 netmask 255.255.255.0//添加IP地址
route add default gw 192.168.1.1//添加网关
启动生效:
vim/etc/sysconfig/network-scripts/ifcfg-eth0//(某些版本中可能没有vim这个编辑器比如centos,大家可能用vi替换)
IPADDR=192.168.1.102//添加IP地址
NETMASK=255.255.255.0//掩码
GATEWAY=192.168.1.1//添加网关
最后结果如下:
DEVICE=eth0
BOOTPROTO=static
IPADDR=192.168.1.102
NETMASK=255.255.255.0
GETEWAY=192.168.1.1
ONBOOT=yes
TYPE=Ethernet
注:BOOTPROTO只有在static(静态)模式下才可以使用设置的IP信息
修改dns
vim/etc/resolv.conf
修改后可即时生效,启动同样有效
形式
加入nameserver=***.***.***.***
最多可有三个,作为上一个失败后的候选
修改host name
即时生效:
hostname fc2
启动生效:
vim/etc/sysconfig/network
形式如下:
NETWORKING=yes
HOSTNAME=rh-linux.fc.org
##########################################################
首先,先了解传统的网络配置命令:
1.使用ifconfig命令配置并查看网络接口情况
示例1:配置eth0的IP,同时激活设备:
ifconfig eth0 192.168.4.1 netmask 255.255.255.0 up
示例2:配置eth0别名设备 eth0:1的IP,并添加路由
ifconfig eth0:1 192.168.4.2
route add–host 192.168.4.2 dev eth0:1
示例3:激活(禁用)设备
ifconfig eth0:1 up(down)
示例4:查看所有(指定)网络接口配置
ifconfig(eth0)
—————————
2.使用route命令配置路由表
示例1:添加到主机路由
route add–host 192.168.4.2 dev eth0:1
route add–host 192.168.4.1 gw 192.168.4.250
示例2:添加到网络的路由
route add–net IP netmask MASK eth0
route add–net IP netmask MASK gw IP
route add–net IP/24 eth1
示例3:添加默认网关
route add default gw IP
示例4:删除路由
route del–host 192.168.4.1 dev eth0:1
示例5:查看路由信息
route或 route-n(-n表示不解析名字,列出速度会比route快)
—————————
3.ARP管理命令
示例1:查看ARP缓存
arp
示例2:添加
arp–s IP MAC
示例3:删除
arp–d IP
—————————
4.ip是iproute2软件包里面的一个强大的网络配置工具,它能够替代一些传统的网络管理工具。
例如:ifconfig、route等,
上面的示例完全可以用下面的ip命令实现,而且ip命令可以实现更多的功能.下面介绍一些示例:
4.0 ip命令的语法
ip [OPTIONS] OBJECT [COMMAND [ARGUMENTS]]
4.1 ip link set–改变设备的属性.缩写:set、s
示例1:up/down起动/关闭设备。
ip link set dev eth0 up
这个等于传统的
ifconfig eth0 up
ifconfig eth0 down
示例2:改变设备传输队列的长度。
参数:txqueuelen NUMBER或者txqlen NUMBER
ip link set dev eth0 txqueuelen 100
示例3:改变网络设备MTU(最大传输单元)的值。
ip link set dev eth0 mtu 1500
示例4:修改网络设备的MAC地址。
参数: address LLADDRESS
ip link set dev eth0 address 00:01:4f:00:15:f1
4.2 ip link show–显示设备属性.缩写:show、list、lst、sh、ls、l
-s选项出现两次或者更多次,ip会输出更为详细的错误信息统计。
示例:
ip-s-s link ls eth0
这个命令等于传统的
ifconfig eth0
—————————
5.1 ip address add–添加一个新的协议地址.缩写:add、a
示例1:为每个地址设置一个字符串作为标签。为了和Linux-2.0的网络别名兼容,这个字符串必须以设备名开头,接着一个冒号,
ip addr add local 192.168.4.1/28 brd+ label eth0:1 dev eth0
等价于
ifconfig eth0:5 192.168.4.1/28
ip addr add local 192.168.4.1/28 dev eth0
示例2:在以太网接口eth0上增加一个地址192.168.20.0,掩码长度为24位(155.155.155.0),标准广播地址,标签为 eth0:Alias:
ip addr add 192.168.4.2/24 brd+ dev eth1 label eth1:1
这个命令等于传统的:
ifconfig eth1:1 192.168.4.2/24
5.2 ip address delete–删除一个协议地址.缩写:delete、del、d
ip addr del 192.168.4.1/24 brd+ dev eth0 label eth0:Alias1
5.3 ip address show–显示协议地址.缩写:show、list、lst、sh、ls、l
ip addr ls eth0
5.4.ip address flush–清除协议地址.缩写:flush、f
示例1:删除属于私网10.0.0.0/8的所有地址:
ip-s-s a f to 10/8
示例2:取消所有以太网卡的IP地址
ip-4 addr flush label“eth0″
—————————
6. ip neighbour–neighbour/arp表管理命令
缩写 neighbour、neighbor、neigh、n
命令 add、change、replace、delete、fulsh、show(或者list)
6.1 ip neighbour add—添加一个新的邻接条目
ip neighbour change–修改一个现有的条目
ip neighbour replace–替换一个已有的条目
缩写:add、a;change、chg;replace、repl
示例1:在设备eth0上,为地址10.0.0.3添加一个permanent ARP条目:
ip neigh add 10.0.0.3 lladdr 0:0:0:0:0:1 dev eth0 nud perm
示例2:把状态改为reachable
ip neigh chg 10.0.0.3 dev eth0 nud reachable
6.2.ip neighbour delete–删除一个邻接条目
示例1:删除设备eth0上的一个ARP条目10.0.0.3
ip neigh del 10.0.0.3 dev eth0
6.3.ip neighbour show–显示网络邻居的信息.缩写:show、list、sh、ls
示例1: ip-s n ls 193.233.7.254
193.233.7.254. dev eth0 lladdr 00:00:0c:76:3f:85 ref 5 used 12/13/20 nud reachable
6.4.ip neighbour flush–清除邻接条目.缩写:flush、f
示例1:(-s可以显示详细信息)
ip-s-s n f 193.233.7.254
—————————
7.路由表管理
7.1.缩写 route、ro、r
7.5.路由表
从Linux-2.2开始,内核把路由归纳到许多路由表中,这些表都进行了编号,编号数字的范围是1到255。另外,
为了方便,还可以在/etc/iproute2/rt_tables中为路由表命名。
默认情况下,所有的路由都会被插入到表main(编号254)中。在进行路由查询时,内核只使用路由表main。
7.6ip route add—添加新路由
ip route change—修改路由
ip route replace—替换已有的路由
缩写:add、a;change、chg;replace、repl
示例1:设置到网络10.0.0/24的路由经过网关193.233.7.65
ip route add 10.0.0/24 via 193.233.7.65
示例2:修改到网络10.0.0/24的直接路由,使其经过设备dummy
ip route chg 10.0.0/24 dev dummy
示例3:实现链路负载平衡.加入缺省多路径路由,让ppp0和ppp1分担负载(注意:scope值并非必需,它只不过是告诉内核,这个路由要经过网关而不是直连的。实际上,如果你知道远程端点的地址,使用via参数来设置就更好了)。
ip route add default scope global nexthop dev ppp0 nexthop dev ppp1
ip route replace default scope global nexthop dev ppp0 nexthop dev ppp1
示例4:设置NAT路由。在转发来自192.203.80.144的数据包之前,先进行网络地址转换,把这个地址转换为193.233.7.83
ip route add nat 192.203.80.142 via 193.233.7.83
示例5:实现数据包级负载平衡,允许把数据包随机从多个路由发出。weight可以设置权重.
ip route replace default equalize nexthop via 211.139.218.145 dev eth0 weight 1 nexthop via 211.139.218.145 dev eth1 weight 1
7.7.ip route delete–删除路由
缩写:delete、del、d
示例1:删除上一节命令加入的多路径路由
ip route del default scope global nexthop dev ppp0 nexthop dev ppp1
7.8.ip route show—列出路由
缩写:show、list、sh、ls、l
示例1:计算使用gated/bgp协议的路由个数
ip route ls proto gated/bgp|wc
1413989179010
示例2:计算路由缓存里面的条数,由于被缓存路由的属性可能大于一行,以此需要使用-o选项
ip-o route ls cloned|wc
159254318707
示例3:列出路由表TABLEID里面的路由。缺省设置是table main。TABLEID或者是一个真正的路由表ID或者是/etc/iproute2/rt_tables文件定义的字符串,
或者是以下的特殊值:
all—列出所有表的路由;
cache—列出路由缓存的内容。
ip ro ls 193.233.7.82 tab cache
示例4:列出某个路由表的内容
ip route ls table fddi153
示例5:列出默认路由表的内容
ip route ls
这个命令等于传统的: route
7.9.ip route flush—擦除路由表
示例1:删除路由表main中的所有网关路由(示例:在路由监控程序挂掉之后):
ip-4 ro flush scope global type unicast
示例2:清除所有被克隆出来的IPv6路由:
ip-6-s-s ro flush cache
示例3:在gated程序挂掉之后,清除所有的BGP路由:
ip-s ro f proto gated/bgp
示例4:清除所有ipv4路由cache
ip route flush cache
*** IPv4 routing cache is flushed.
7.10ip route get—获得单个路由.缩写:get
Linux怎么设置IP,子网掩码和网关
linux一般使用ifconfig命令修改linux主机的ip、网关或子网掩码。 1.命令格式: ifconfig [网络设备] [参数] 2.命令功能: ifconfig命令用来查看和配置网络设备。当网络环境发生改变时可通过此命令对网络进行相应的配置。 3.命令参数: up启动指定网络设备/网卡。 down关闭指定网络设备/网卡。该参数可以有效地阻止通过指定接口的IP信息流,如果想永久地关闭一个接口,我们还需要从核心路由表中将该接口的路由信息全部删除。 arp设置指定网卡是否支持ARP协议。-promisc设置是否支持网卡的promiscuous模式,如果选择此参数,网卡将接收网络中发给它所有的数据包-allmulti设置是否支持多播模式,如果选择此参数,网卡将接收网络中所有的多播数据包-a显示全部接口信息-s显示摘要信息(类似于 netstat-i) add给指定网卡配置IPv6地址 del删除指定网卡的IPv6地址<硬件地址>配置网卡最大的传输单元 mtu<字节数>设置网卡的最大传输单元(bytes) netmask<子网掩码>设置网卡的子网掩码。掩码可以是有前缀0x的32位十六进制数,也可以是用点分开的4个十进制数。如果不打算将网络分成子网,可以不管这一选项;如果要使用子网,那么请记住,网络中每一个系统必须有相同子网掩码。 tunel建立隧道 dstaddr设定一个远端地址,建立点对点通信-broadcast<地址>为指定网卡设置广播协议-pointtopoint<地址>为网卡设置点对点通讯协议 multicast为网卡设置组播标志 address为网卡设置IPv4地址 txqueuelen<长度>为网卡设置传输列队的长度 4.使用实例:实例1:显示网络设备信息(激活状态的)命令: ifconfig输出: [root@localhost~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:50:56:BF:26:20 inet addr:192.168.120.204 Bcast:192.168.120.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:8700857 errors:0 dropped:0 overruns:0 frame:0 TX packets:31533 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:596390239(568.7 MiB) TX bytes:2886956(2.7 MiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:68 errors:0 dropped:0 overruns:0 frame:0 TX packets:68 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:2856(2.7 KiB) TX bytes:2856(2.7 KiB)说明: eth0表示第一块网卡,其中 HWaddr表示网卡的物理地址,可以看到目前这个网卡的物理地址(MAC地址)是 00:50:56:BF:26:20 inet addr用来表示网卡的IP地址,此网卡的 IP地址是 192.168.120.204,广播地址, Bcast:192.168.120.255,掩码地址Mask:255.255.255.0 lo是表示主机的回坏地址,这个一般是用来测试一个网络程序,但又不想让局域网或外网的用户能够查看,只能在此台主机上运行和查看所用的网络接口。比如把 HTTPD服务器的指定到回坏地址,在浏览器输入 127.0.0.1就能看到你所架WEB网站了。但只是您能看得到,局域网的其它主机或用户无从知道。第一行:连接类型:Ethernet(以太网)HWaddr(硬件mac地址)第二行:网卡的IP地址、子网、掩码第三行:UP(代表网卡开启状态)RUNNING(代表网卡的网线被接上)MULTICAST(支持组播)MTU:1500(最大传输单元):1500字节第四、五行:接收、发送数据包情况统计第七行:接收、发送数据字节数统计信息。实例2:启动关闭指定网卡命令: ifconfig eth0 up ifconfig eth0 down输出:说明: ifconfig eth0 up为启动网卡eth0;ifconfig eth0 down为关闭网卡eth0。ssh登陆linux服务器操作要小心,关闭了就不能开启了,除非你有多网卡。实例3:为网卡配置和删除IPv6地址命令: ifconfig eth0 add 33ffe:3240:800:1005::2/64 ifconfig eth0 del 33ffe:3240:800:1005::2/64输出:说明: ifconfig eth0 add 33ffe:3240:800:1005::2/64为网卡eth0配置IPv6地址; ifconfig eth0 add 33ffe:3240:800:1005::2/64为网卡eth0删除IPv6地址;练习的时候,ssh登陆linux服务器操作要小心,关闭了就不能开启了,除非你有多网卡。实例4:用ifconfig修改MAC地址命令: ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE输出: [root@localhost~]# ifconfig eth0 down//关闭网卡 [root@localhost~]# ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE//修改MAC地址 [root@localhost~]# ifconfig eth0 up//启动网卡 [root@localhost~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:AA:BB:CC:DD:EE inet addr:192.168.120.204 Bcast:192.168.120.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:8700857 errors:0 dropped:0 overruns:0 frame:0 TX packets:31533 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:596390239(568.7 MiB) TX bytes:2886956(2.7 MiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:68 errors:0 dropped:0 overruns:0 frame:0 TX packets:68 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:2856(2.7 KiB) TX bytes:2856(2.7 KiB) [root@localhost~]# ifconfig eth0 hw ether 00:50:56:BF:26:20//关闭网卡并修改MAC地址 [root@localhost~]# ifconfig eth0 up//启动网卡 [root@localhost~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:50:56:BF:26:20 inet addr:192.168.120.204 Bcast:192.168.120.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:8700857 errors:0 dropped:0 overruns:0 frame:0 TX packets:31533 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:596390239(568.7 MiB) TX bytes:2886956(2.7 MiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:68 errors:0 dropped:0 overruns:0 frame:0 TX packets:68 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:2856(2.7 KiB) TX bytes:2856(2.7 KiB)说明:实例5:配置IP地址命令:输出: [root@localhost~]# ifconfig eth0 192.168.120.56 [root@localhost~]# ifconfig eth0 192.168.120.56 netmask 255.255.255.0 [root@localhost~]# ifconfig eth0 192.168.120.56 netmask 255.255.255.0 broadcast 192.168.120.255说明: ifconfig eth0 192.168.120.56给eth0网卡配置IP地:192.168.120.56 ifconfig eth0 192.168.120.56 netmask 255.255.255.0给eth0网卡配置IP地址:192.168.120.56,并加上子掩码:255.255.255.0 ifconfig eth0 192.168.120.56 netmask 255.255.255.0 broadcast 192.168.120.255/给eth0网卡配置IP地址:192.168.120.56,加上子掩码:255.255.255.0,加上个广播地址: 192.168.120.255实例6:启用和关闭ARP协议命令: ifconfig eth0 arp ifconfig eth0-arp输出: [root@localhost~]# ifconfig eth0 arp [root@localhost~]# ifconfig eth0-arp说明: ifconfig eth0 arp开启网卡eth0的arp协议; ifconfig eth0-arp关闭网卡eth0的arp协议;实例7:设置最大传输单元命令: ifconfig eth0 mtu 1500输出: [root@localhost~]# ifconfig eth0 mtu 1480 [root@localhost~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:50:56:BF:26:1F inet addr:192.168.120.203 Bcast:192.168.120.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1480 Metric:1 RX packets:8712395 errors:0 dropped:0 overruns:0 frame:0 TX packets:36631 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:597062089(569.4 MiB) TX bytes:2643973(2.5 MiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:9973 errors:0 dropped:0 overruns:0 frame:0 TX packets:9973 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:518096(505.9 KiB) TX bytes:518096(505.9 KiB) [root@localhost~]# ifconfig eth0 mtu 1500 [root@localhost~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:50:56:BF:26:1F inet addr:192.168.120.203 Bcast:192.168.120.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:8712548 errors:0 dropped:0 overruns:0 frame:0 TX packets:36685 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:597072333(569.4 MiB) TX bytes:2650581(2.5 MiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:9973 errors:0 dropped:0 overruns:0 frame:0 TX packets:9973 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:518096(505.9 KiB) TX bytes:518096(505.9 KiB) [root@localhost~]#说明:设置能通过的最大数据包大小为 1500 bytes备注:用ifconfig命令配置的网卡信息,在网卡重启后机器重启后,配置就不存在。要想将上述的配置信息永远的存的电脑里,那就要修改网卡的配置文件了。
好了,本文到此结束,如果可以帮助到大家,还望关注本站哦!