linux下上网配置
首页->学习资料->linux教程->linux基础 关键词: 发布时间:2016-02-26 10:57:27 浏览次数:1491

第一种方式:

用先root用户登录,然后输入setup回车,按键盘上的向上和向下的箭头可以移动,选择network configuration按回车

然后看到如下,一个是配置ip地址,一个是配置dns的

选中第一个网卡按回车

然后看到如下,箭头所指*表示自动获取ip,tab键键换到此项上按空格后,下面三行可以输入,表示手动设置ip,子网掩码,网关

设置好后保存并退出

然后重启网络服务:

命令如下:

[root@localhost hurong]# /etc/rc.d/init.d/network restart


然后可以用ifconfig(window下是ipconfig)查看网络配置,显示结果类似如下:

[root@localhost hurong]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:EF:D6:EA  
          inet addr:192.168.109.129  Bcast:192.168.109.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:feef:d6ea/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1452 errors:0 dropped:0 overruns:0 frame:0
          TX packets:493 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:346365 (338.2 KiB)  TX bytes:38466 (37.5 KiB)
          Interrupt:19 Base address:0x2024

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:16436  Metric:1
          RX packets:180 errors:0 dropped:0 overruns:0 frame:0
          TX packets:180 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:16855 (16.4 KiB)  TX bytes:16855 (16.4 KiB)

[root@localhost hurong]#


第二种方式:
ifconfig 网卡 ip地址

ifconfig 网卡 network 子网掩码

只不过这种修改方式是临时的,如果服务器重启,又会恢复到系统的初始配置


如下, 我们临时将ip修改为192.168.109.8

[root@localhost hurong]# ifconfig eth0 192.168.109.8

如果回车后没有任何提示即表示修改成功,然后用ifconfig命令可以看到ip已被成功修改


[root@localhost hurong]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:EF:D6:EA  
          inet addr:192.168.109.8  Bcast:192.168.109.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:feef:d6ea/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1605 errors:0 dropped:0 overruns:0 frame:0
          TX packets:495 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:357249 (348.8 KiB)  TX bytes:38850 (37.9 KiB)
          Interrupt:19 Base address:0x2024

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:16436  Metric:1
          RX packets:180 errors:0 dropped:0 overruns:0 frame:0
          TX packets:180 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:16855 (16.4 KiB)  TX bytes:16855 (16.4 KiB)

[root@localhost hurong]#


第三种修改方法是直接去修改上网的配置文件

命令如下:

[root@localhost hurong]# vi /etc/sysconfig/network-scripts/ifcfg-eth0

然后可以看到这里面的配置,由于我在第一种配置中设置的自动获取ip,所以这里面看不到ip地址,只看得到我设置的dns1=114.114.114.114 dns2=8.8.8.8

EVICE=eth0
BOOTPROTO=dhcp
HWADDR=00:0c:29:ef:d6:ea
IPV6INIT=yes
NM_CONTROLLED=yes
ONBOOT=yes
TYPE=Ethernet
UUID="d97313ec-8da7-4c64-aedb-1c12cca37958"
DNS2=8.8.8.8
DNS1=114.144.114.114
USERCTL=no
PEERDNS=yes

如果进行了修改,记得重启一下网络服务:

[root@localhost hurong]# /etc/rc.d/init.d/network restart

也可以用以下命令重启网络服务:

[root@localhost hurong]# service network restart


有兴趣的话可以切换到这个配置目录下看看,里面有很多与网络配置有关的文件:

[root@localhost hurong]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ls
ifcfg-eth0   ifdown-isdn    ifup-aliases  ifup-plusb     init.ipv6-global
ifcfg-lo     ifdown-post    ifup-bnep     ifup-post      net.hotplug
ifdown       ifdown-ppp     ifup-eth      ifup-ppp       network-functions
ifdown-bnep  ifdown-routes  ifup-ippp     ifup-routes    network-functions-ipv6
ifdown-eth   ifdown-sit     ifup-ipv6     ifup-sit
ifdown-ippp  ifdown-tunnel  ifup-isdn     ifup-tunnel
ifdown-ipv6  ifup           ifup-plip     ifup-wireless
[root@localhost network-scripts]# pwd
/etc/sysconfig/network-scripts
[root@localhost network-scripts]#


另外:

如果要让当前系统(win7)与虚拟机上的linux(centos6.4)通讯(ping通)

可以将他们的ip地址设置为同一个网段即可;

赞:(0)
踩:(0)
相关文章
win7中将文件拷贝到虚拟机linux下
linux下切换root用户
linux目录结构
为linux指定运行级别
linux下vi编辑器的使用
linux下安装java
linux下安装tomcat
linux下安装mysql
linux下安装五笔输入法
linux下在终端命令行中显示中文
热门文章
win7中将文件拷贝到虚拟机linux下
phpexcel设置行高及列宽,背景颜色,
rabbitmq无法启动
intellij idea不显示git push按钮
php7中使用mongodb的aggregate进行
centos7.4 64位下swoole安装及配置
laravel页面静态化的方法
navicate连接mycat报1184错误
单点登录sso原理及php实现方式及de
devops-jenkins容器为pending状态
好评文章
phpexcel设置行高及列宽,背景颜色,
php7中使用mongodb的aggregate进行
intellij idea打开文件所在文件夹
windows下使用MongoDB Compass Com
win7中将文件拷贝到虚拟机linux下
laravel 中悲观锁 & 乐观锁的使用
单点登录sso原理及php实现方式及de
navicate连接mycat报1184错误
rabbitmq无法启动
laravel整合dingo/api方法步骤:jwt
标签
rabbitmq mysql备份 elasticsearch golang swoole
我的项目
【github】www.github.com/hurong241
【码云】gitee.com/hu_rong/projects
【docker hub】hub.docker.com/repositories/hurong241
【packagist】packagist.org/users/hurong241/packages
站点信息
建站时间:2011年
文章数:607篇
浏览数:935521
粤ICP备18028092号-1  微信:hurong241