linux网络命令小结(adsl拨号)

前言:在安装完虚拟机后,可以在windows的cmd里,输入ipconfig命令,查看到有3个适配器。第一个是本地连接,第二个是VMware Network Adapter VMnet1,第三个是VMware NetworkAdapter VMnet8。

1、本地连接显示的是自己电脑网卡的配置信息。

2、vmnet1是虚拟机网络连接类型中的host-only,也就是说,选择用vmnet1的话就相当于VMware给你提供了一个虚拟交换机,仅将虚拟机和真实系统连上了,虚拟机可以与真实系统相互共享文件,但是虚拟机无法访问外部互联网。

3、vmnet8是NAT,就是网络地址转换,相当于给你一个虚拟交换机,将虚拟机和真实系统连上去了,同时这台虚拟交换机又和外部互联网相连。

列出几个常用的网络配置文件:

1、/etc/sysconfig/network----系统启动所用的最基本的网络信息

内容如下:

         NETWORKING=yes

         HOSTNAME=localhost.localdomain-------主机名最好与hosts里面保持一致

2、/etc/hosts----完成主机名映射为IP地址的功能,第一列是ip,第二列是主机名。

内容如下:

         127.0.0.1   localhost localhost.localdomain localhost4localhost4.localdomain4

         ::1         localhost localhost.localdomainlocalhost6 localhost6.localdomain6

在解析域名时,例如访问网站或者ping域名,系统会默认先查看hosts文件,如有匹配的地址,则转换为对应的ip,如果没有,则请求域名解析服务器中的对应信息。

3、/etc/resolv.conf ----域名服务客户端的配置文件,用于指定域名服务器的位置

内容如下:

         # Generated byNetworkManager

         domain localdomain

         search localdomain

         nameserver192.168.174.2

4、/etc/sysconfig/network-scripts/ifcfg-eth0----主要到最后的eth0,我们可以设置多块网卡,每一个网卡对应一个ethx,我们可以在这里面定义接口的的信息。这个文件经常使用。

内容入下:

         DEVICE="eth0"----设备接口是eth0

         BOOTPROTO="dhcp"----ip获得方式是dhcp,我们可以设置为static,配置上一个固定ip

         HWADDR="00:0C:29:83:9D:F3"-----物理地址

         IPV6INIT="yes"----是否使用ipv6

         NM_CONTROLLED="yes"

         ONBOOT="yes"----启动时生效

         TYPE="Ethernet"----网络类型

         UUID="05cde146-65a9-49c7-82c0-53bd1d46239e"

         还可以加上IPADDR----ip地址和NETMASK----子网掩码

列出几个常用的网络命令

1、ifconfig  查看所有网络接口的配置信息

结果如下:

         eth0      Link encap:Ethernet  HWaddr 00:0C:29:83:9D:F3 

          inetaddr:192.168.174.164 Bcast:192.168.174.255 Mask:255.255.255.0

          inet6 addr:fe80::20c:29ff:fe83:9df3/64 Scope:Link

          UP BROADCAST RUNNINGMULTICAST  MTU:1500  Metric:1

          RX packets:38897errors:0 dropped:0 overruns:0 frame:0

          TX packets:13611errors:0 dropped:0 overruns:0 carrier:0

          collisions:0txqueuelen:1000

          RX bytes:47888291(45.6 MiB)  TX bytes:740198 (722.8 KiB)

 

lo        Link encap:LocalLoopback 

          inetaddr:127.0.0.1  Mask:255.0.0.0

          inet6 addr: ::1/128Scope:Host

          UP LOOPBACKRUNNING  MTU:16436  Metric:1

          RX packets:8errors:0 dropped:0 overruns:0 frame:0

          TX packets:8errors:0 dropped:0 overruns:0 carrier:0

          collisions:0txqueuelen:0

          RX bytes:480 (480.0 b)  TX bytes:480 (480.0 b)

         1.1、 ifconfigethx ip地址/掩码----修改某网络接口IP地址和掩码,临时生效

                    ifconfig eth0 192.168.174.11 netmask 255.255.255.0

         1.2、 ifconfigethx:x ip netmask ip----配置网卡多个IP地址

                    ifconfig eth0:0 192.168.174.21 netmask255.255.255.0

         结果如下:多出的内容。

          eth0:0  Linkencap:Ethernet  HWaddr00:0C:29:83:9D:F3 

          inetaddr:192.168.174.21  Bcast:192.168.174.255  Mask:255.255.255.0

          UP BROADCAST RUNNINGMULTICAST  MTU:1500  Metric:1

         1.3、ifconfigeth0 up | ifconfig eth0 down--激活或者禁用设备

                    ifconfig eth0:0 down

         结果如下:

          eth0:0的信息都没了,up一下就有了。

2、service networkstop|start|restart----服务停止,开启,重启

3、route add -net networkip|defaultgw ip-----------route可以查看路由表

         我们可以增加静态路由信息,来使得本机具有静态路由的转发功能。

         例如:default是默认转发口,在目标网络地址没有匹配到时,从默认口出去。如果某机器设置两块网卡且不在同一网段,就可以设置这个选项使得本机就有ip转发的功能。

4、echo"1">/proc/sys/net/ipv4/ip_forward----开启路由转发

         默认情况下是不转发的,要实现本机的路由功能就要把这个文件的内容设置为1

5、ping ip|域名   traceroute域名---测试网络通畅性      追踪路由信息

 

setup命令

图形化的配置界面,我们可以从弹出的选项中选择我们需要设置的内容,非常的方便。

补充一个adsl拨号连接的配置方法

第一步:安装adsl拨号服务

[root@localhost network-scripts]# yum install rp-pppoe
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirrors.btte.net
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package rp-pppoe.x86_64 0:3.10-16.el6 will be installed
--> Finished Dependency Resolution


Dependencies Resolved


================================================================================
 Package            Arch             Version               Repository      Size
================================================================================
Installing:
 rp-pppoe           x86_64           3.10-16.el6           base            97 k


Transaction Summary
================================================================================
Install       1 Package(s)


Total download size: 97 k
Installed size: 237 k
Is this ok [y/N]: y
Downloading Packages:
rp-pppoe-3.10-16.el6.x86_64.rpm                          |  97 kB     00:00     
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Importing GPG key 0xC105B9DE:
 Userid : CentOS-6 Key (CentOS 6 Official Signing Key) <centos-6-key@centos.org>
 Package: centos-release-6-5.el6.centos.11.1.x86_64 (@anaconda-CentOS-201311272149.x86_64/6.5)
 From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : rp-pppoe-3.10-16.el6.x86_64                                  1/1 
  Verifying  : rp-pppoe-3.10-16.el6.x86_64                                  1/1 


Installed:
  rp-pppoe.x86_64 0:3.10-16.el6                                                 


Complete!

第二步:设置sdsl参数

[root@localhost network-scripts]# adsl-setup 


Welcome to the PPPoE client setup.  First, I will run some checks on
your system to make sure the PPPoE client is installed properly...




LOGIN NAME


Enter your Login Name (default test): adsl_test


INTERFACE


Enter the Ethernet interface connected to the PPPoE modem
For Solaris, this is likely to be something like /dev/hme0.
For Linux, it will be ethX, where 'X' is a number.
(default eth0): eth1


Do you want the link to come up on demand, or stay up continuously?
If you want it to come up on demand, enter the idle time in seconds
after which the link should be dropped.  If you want the link to
stay up permanently, enter 'no' (two letters, lower-case.)
NOTE: Demand-activated links do not interact well with dynamic IP
addresses.  You may have some problems with demand-activated links.
Enter the demand value (default no): 


DNS


Please enter the IP address of your ISP's primary DNS server.
If your ISP claims that 'the server will provide dynamic DNS addresses',
enter 'server' (all lower-case) here.
If you just press enter, I will assume you know what you are
doing and not modify your DNS setup.
Enter the DNS information here: Server
Please enter the IP address of your ISP's secondary DNS server.
If you just press enter, I will assume there is only one DNS server.
Enter the secondary DNS server address here: Server


PASSWORD


Please enter your Password: 
Please re-enter your Password: 
Sorry, the passwords do not match.  Try again? (y/n)y


PASSWORD


Please enter your Password: 
Please re-enter your Password: 


USERCTRL


Please enter 'yes' (three letters, lower-case.) if you want to allow
normal user to start or stop DSL connection (default yes): no


FIREWALLING


Please choose the firewall rules to use.  Note that these rules are
very basic.  You are strongly encouraged to use a more sophisticated
firewall setup; however, these will provide basic security.  If you
are running any servers on your machine, you must choose 'NONE' and
set up firewalling yourself.  Otherwise, the firewall rules will deny
access to all standard servers like Web, e-mail, ftp, etc.  If you
are using SSH, the rules will block outgoing SSH connections which
allocate a privileged source port.


The firewall choices are:
0 - NONE: This script will not set any firewall rules.  You are responsible
          for ensuring the security of your machine.  You are STRONGLY
          recommended to use some kind of firewall rules.
1 - STANDALONE: Appropriate for a basic stand-alone web-surfing workstation
2 - MASQUERADE: Appropriate for a machine acting as an Internet gateway
                for a LAN
Choose a type of firewall (0-2): 0


Start this connection at boot time


Do you want to start this connection at boot time?
Please enter no or yes (default no):no


** Summary of what you entered **


Ethernet Interface: eth1
User name:          adsl_test
Activate-on-demand: No
Primary DNS:        Server
Secondary DNS:      Server
Firewalling:        NONE
User Control:       no
Accept these settings and adjust configuration files (y/n)? y
Adjusting /etc/sysconfig/network-scripts/ifcfg-ppp0
Adjusting /etc/resolv.conf
  (But first backing it up to /etc/resolv.conf.bak)
Adjusting /etc/ppp/chap-secrets and /etc/ppp/pap-secrets
  (But first backing it up to /etc/ppp/chap-secrets.bak)
  (But first backing it up to /etc/ppp/pap-secrets.bak)






Congratulations, it should be all set up!


Type '/sbin/ifup ppp0' to bring up your xDSL link and '/sbin/ifdown ppp0'
to bring it down.
Type '/sbin/pppoe-status /etc/sysconfig/network-scripts/ifcfg-ppp0'
to see the link status.

第三步:启动或关闭连接

adsl-start       adsl-stop

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值