Linux Basics: 2, network configuration and connection using putty

Source: Internet
Author: User
Tags centos server

First, network configuration


1. View network Configuration

Command: Ifconfig

=========================================================================[[email protected] ~]#  ifconfigeth0      link encap:ethernet  hwaddr 00:0c:29 :f4:a4:5a          inet addr:192.168.0.41   bcast:192.168.0.255  mask:255.255.255.0           inet6 addr: fe80::20c:29ff:fef4:a45a/64 scope:link           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1           rx packets:690437 errors:0 dropped:0  overruns:0 frame:0          tx packets:8209  errors:0 dropped:0 overruns:0 carrier:0           collisions:0 txqueuelen:1000          rx bytes:65851958  (62.8  MIB)   TX bytes:1041079  (1016.6 kib)            Interrupt:19 Base address:0x2000lo         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:32 errors:0 dropped:0 overruns:0 frame:0           TX packets:32 errors:0 dropped:0 overruns:0  Carrier:0          collisions:0 txqueuelen:0           RX bytes:2688  (2.6 kib)   TX bytes:2688  (2.6  KiB) ==========================================================================


#linux下的网卡名称命名规则是, eth0, eth1 ...

#lo网卡的功能是在计算机内部进行信息交换


2. DHCP automatically obtains IP address

Command: Dhclient

#当我们刚刚安装完系统, if you do not configure the network during the installation process, you will find that the Eth0 network card is not started, this time we use to get dhclient to obtain IP

#使用此命令的前提是网卡配置文件中BOOTPROTO设置为dhcp

=================================================================[[email protected] ~]# cat/etc/sysconfig/ Network-scripts/ifcfg-eth0device=eth0hwaddr=00:0c:29:f4:a4:5atype=ethernetuuid= ab0c175d-2938-423b-9546-eab0303a12f5onboot=yesnm_controlled=yesbootproto=dhcp================================= ================================


3. Set the static IP

================================================================== #配置文件 [[email protected] ~]#  ls /etc/sysconfig/network-scripts/ifcfg*/etc/sysconfig/network-scripts/ifcfg-eth0/etc/sysconfig/ network-scripts/ifcfg-lo# can see the configuration files for eth0 and lo, let's configure the eth0[[email protected] ~]# vi /etc/ sysconfig/network-scripts/ifcfg-eth0# Modifying the eth0 configuration file device=eth0hwaddr=00:0c:29:f4:a4:5atype=ethernetuuid= ab0c175d-2938-423b-9546-eab0303a12f5onboot=yesnm_controlled=yesbootproto=static             #这里设置为staticIPADDR =192.168.0.41          #配置IP地址GATEWAY =192.168.0.1         #配置网关NETMASK =255.255.255.0        #配置子网掩码DNS1 =192.168.0.1             #配置DNS [[email protected] ~]# service network restart# Restart Network Service, Let's look at the network information again to see [[email protected] ~]# ifconfig eth0eth0      link encap:ethernet  hwaddr  00:0c:29:f4:a4:5a          inet addr:192.168.0.41   Bcast:192.168.0.255  Mask:255.255.255.0           inet6 addr: fe80::20c:29ff:fef4:a45a/64 Scope:Link           up broadcast running multicast  mtu:1500  metric:1           rx packets:49787 errors:0 dropped:0  overruns:0 frame:0          tx packets:5770  errors:0 dropped:0 overruns:0 carrier:0           collisions:0 txqueuelen:1000          rx  bytes:10866317 (10.3 mib)   TX bytes:538852  (526.2 kib)            Interrupt:19 Base address:0x2000            #ip地址已经变为192 168.0.41 the =================================================================.

4, configuring multiple IPs

=================================================================[[email protected] ~]# cd  /etc/sysconfig/network-scripts/[[email protected] network-scripts]# cp ifcfg-eth0  ifcfg-eth0:1[[email protected] network-scripts]# vi ifcfg-eth0:1device=eth0:1hwaddr= 00:0c:29:f4:a4:5atype=ethernetuuid=ab0c175d-2938-423b-9546-eab0303a12f5onboot=yesnm_controlled=yesbootproto= static           ipaddr=192.168.0.42          #配置IP地址为192 .168.0.42gateway=192.168.0.1         NETMASK=255.255.255.0      DNS1=192.168.0.1          [[email protected] network-scripts]# service network  restartshutting down interface eth0:               &nbsP;               [  ok   ]Shutting down loopback interface:                           [   OK  ]Bringing up loopback interface:                              [  OK  ]Bringing up interface eth0:   determining if ip address 192.168.0.41 is already i                         n use for device eth0...                                                              [  OK  ]                                                                #让我们查看一下ip地址 (with ip addr) [[email protected] network-scripts]# ip addr |  Grep  eth02: eth0: <broadcast,multicast,up,lower_up> mtu 1500 qdisc  pfifo_fast state unknown qlen 1000    inet 192.168.0.41/24  brd 192.168.0.255 scope global eth0    inet 192.168.0.42/24 brd  192.168.0.255 scope global secondary eth0    [[email protected]  ~]# ifconfig |grep -a1 eth0         # View Eth0 Nic Eth0      link encap:ethernet  hwaddr 00:0c:29:f4:a4 : 5a          inet addr:192.168.0.41  bcast :192.168.0.255  mask:255.255.255.0--eth0:1    link encap:ethernet   hwaddr 00:0c:29:f4:a4:5a          inet addr : 192.168.0.42  bcast:192.168.0.255  mask:255.255.255.0# can see two IP addresses Oh, let's ping to test whether the new IP is unobstructed [[ email protected] network-scripts]# ping -c 5 192.168.0.42ping 192.168.0.42   (192.168.0.42)  56 (+)  bytes of data.64 bytes from 192.168.0.42: icmp_seq=1 ttl=64 time=0.075  ms64 bytes from 192.168.0.42: icmp_seq=2 ttl=64 time=0.042 ms64  Bytes from 192.168.0.42: icmp_seq=3 ttl=64 time=0.042 ms64 bytes from  192.168.0.42: icmp_seq=4 ttl=64 time=0.043 ms64 bytes from  192.168.0.42: icmp_seq=5 ttl=64 time=0.044 ms--- 192.168.0.42 ping  statistics ---5 packets transmitted, 5 received, 0% packet loss,  time 4050msrtt min/avg/max/mdev = 0.042/0.049/0.075/0.013 ms========================= ==========================================

#上面介绍的修改配置文件的方式可以使配置永久生效

#当然你也可以用一种临时增加ip的方法: "Ifconfig eth0:1 192.168.0.42 netmask 255.255.255.0 up"


Second, connect CentOS with putty


1, Putty Introduction

Putty is a small, easy-to-access remote connection software for SSH-connected Linux servers under Windows.

Official website: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html


2, putty installation and regular connection

Installation: Putty installation is very simple, only the default options and the next step is good;

Prerequisites: 1, the need for the CentOS server IP address, 2, the need to open the SSHD service, and know the port of the service;

======================================================================== #利用ifconfig来查看IP地址 [[email protected] ~]# Ifconfig eth0 |grep "inet addr" inet addr:192.168.0.41 bcast:192.168.0.255 mask:255.255.255.0 #查看sshd服 To open the sshd configuration file, the path is "/etc/ssh/sshd_config" [[email protected] ~]# cat/etc/ssh/sshd_config |grep port#port 22# Gatewayports no========================================================================

Open the Putty client, enter the IP and port you obtained, and then click Open to connect properly.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/59/BC/wKioL1Td8Y3C9ONSAAIf9rzmqPw983.jpg "title=" Qq20150213202431.png "alt=" Wkiol1td8y3c9onsaaif9rzmqpw983.jpg "/>

#sshd的默认port就是22, of course, it is also illegal to be very fond of attacking a port, in order to be safe, can get rid of the other


#使用上面的基本设置就能保证你正常使用putty去访问Centos了, but if you want to use putty to connect to CentOS remotely, you can use the following settings to enhance security.

3. Key Login CentOS

#先用putty远程连接上Centos;


#用putty自带软件PUTTYGEN. exe to generate the key (the build process needs to shake the mouse), save the private key to the local, copy the public key content


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/59/BF/wKiom1Td8daSfXX8AAGfDuXe-T8664.jpg "title=" Qq20150213204218.png "alt=" Wkiom1td8dasfxx8aagfduxe-t8664.jpg "/>


The progress bar will go up to 100% during mouse shaking.


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/59/BC/wKioL1Td9PWDGqYZAAKd0d9ktiw666.jpg "title=" Qq20150213204352.png "alt=" Wkiol1td9pwdgqyzaakd0d9ktiw666.jpg "/>

#复制公钥内容

#点击save private key to save the private key to a local

#当然, if you want to be more secure, you can set the private key access password at key passphrase


# create/root/.ssh directory on Linux, change permissions

====================================================[[email protected] ~]# Mkdir/root/.ssh[[email protected] ~]# chmod 700/root/.ssh[[email protected] ~]# ll-d/root/.sshdrwx------. 2 root root 4096 Feb 04:42/root/.ssh #权限为700意味着只有root用户本身可以访问和修改此目录 =============================================== =====


#把公钥内容粘贴入/root/.ssh/authorized_keys, you need to change this file permission to 600

======================================================================================[[email protected]  ~]# cd /root/.ssh[[email protected] .ssh]# vi authorized_keys************* #按下i键进入编辑模式 #putty The right mouse button is the meaning of sticky, click the right mouse button to paste the public key content into this file ssh-rsa  aaaab3nzac1yc2e*****jqaaaqeajs4qjvak3gql6uz/jptmmqmmcrkg02+dfqtoy+5slew2yw0lzzkvmc+bv4cbov3wcsywu0spum+ va6ardtx3mzbuhp3pvueko2tmx3nap9bvlh/tebkdnbi+gay7sk5c67q0dzue7yndz/lsy17ejw4pcz1xs4w+wjncp3s7opu7cjwgdl1ta+ ocktd/toipwfg6m7hvuzy4zr82zqutb/3df4hl3vpaaurfwoxhqeh0yngoaohxpcyvgijijbo+********/ sbcvne7lqkwfpjzsdqww8s5ijhjkhaaxhntxfbsw4v9td8g4wkc8bwj7ubczd19wngfygtbiq== rsa-key-20150213# Press the ESC key, Leave edit mode # input: Wq and press ENTER, ":" means you can enter a command; " W "means write;" Q "means quit." [[email protected] .ssh]# chmod 600  authorized_keys# permissions 600 for normal files means that this file can only be read and written by Root =========================================================== =========================== 


# (This step is not required) turn off SELinux

=====================================================[[email protected]. ssh]# setenforce 0[[email protected]. ssh]# getenforcepermissive=====================================================

#设置PuTTY客户端 (the current connection needs to be closed at this time)

#点左侧SSH, select Auth and click "Browse" on the right to select the private key that we saved to the local

#最后记得去session处保存一下, otherwise this process will need to select the private key again after the next logon process.


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/59/BF/wKiom1Td-uqQAyuKAAJk7Lf_xlo442.jpg "title=" Qq20150213212129.png "alt=" Wkiom1td-uqqayukaajk7lf_xlo442.jpg "/>


#登陆时如果你设置了密码保护私钥的话, you need to enter this password


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/59/BC/wKioL1Td_A-ic6-5AAF0fZbT-tY901.jpg "title=" Qq20150213212259.png "alt=" Wkiol1td_a-ic6-5aaf0fzbt-ty901.jpg "/>


At this point, we have successfully set the key login complete

This article is from the "30 Demon People" blog, please make sure to keep this source http://301ren.blog.51cto.com/8887653/1614384

Linux Basics: 2, network configuration and connection using putty

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.