لینوکس و شبکه

لینوکس و شبکه
طبقه بندی موضوعی
آخرین مطالب
  • ۹۹/۱۱/۱۳
    java

۲۴ مطلب با موضوع «Network/Internet» ثبت شده است

۲۹
فروردين
1- sudo apt-get install openssh-client
2- ssh-keygen -t rsa
    . Enter file in which to save the key (/home/user/.ssh/id_rsa)
    . Enter passphrase (empty for no passphrase) # can donot use passphrass
    . Enter same passphrase again
3- check :
    . Public Key: /home/user/.ssh/id_rsa.pub
    . Private Key: /home/user/.ssh/id_rsa    

4- ssh-copy-id user@YourServerIPAddress    
or
cat ~/.ssh/id_rsa.pub | ssh User@YourServerIPAddress “mkdir -p ~/.ssh && cat >>  ~/.ssh/authorized_keys”
or
scp /home/user/.ssh/id_rsa.pub  user@YourServerIPAddress:/home/user/.ssh
  • behrooz mohamadi nsasab
۲۵
بهمن
sudo apt install builde-essential software-properties-common sshpass git htop icedtea-netx torsocks tor resolvconf python3-pip \
 bash-completion unzip bzip2 mlocate lshw net-tools shellinabox telnet bash nmap bc openjdk sudo wget curl ftp parted* gparted \
 socat  nload
sudo yum groupinstall 'Development Tools'
sudo yum install icedtea-web  git sshpass firewalld  bash-completion torsocks unzip bzip2 mlocate lshw \
 net-tools shellinabox telnet  tor bash  kernel-tools* linux-firmware openssh openssh-server openssh-client \
 nmap bc  java-11-openjdk-devel ftp ftplib vim kernel-devel kernel-headers  yum-utils wget curl sudo lsof \
 parted* socat nload
  • behrooz mohamadi nsasab
۱۴
بهمن

قصد داریم از طریق پروکسی به یک سرور که اینترنت ندارد اینترنت بدهیم

 

سیستم بدون اینترنت:  192.168.10.173

سیستم دارای اینترنت: 192.168.10.148 با یوزر behrooz

 

yum

این دو دستور را درسرور 192.168.10.173 وارد نمایید:

1-add to /etc/yum.conf:
  proxy=socks5h://localhost:xxxx

2-ssh -N -D XXXX behrooz@192.168.10.148

URL

 

 

 

APT

دستورات را درسرور 192.168.10.173 وارد نمایید:

1-vim /etc/apt/apt.conf.d/behrooz
  Acquire::http::proxy "socks5h://localhost:XXXX";
2-ssh -N -D XXXX behrooz@192.168.10.148

URL

  • behrooz mohamadi nsasab
۱۳
بهمن

مراحل نصب یک نسخه جدید از جاوا

شناساندن جاوا(JRE)

sudo update-alternatives --install "/usr/bin/java" "java" "<Custom PATH>/bin/java" 0

شناساندن جاوا(JDK)

sudo update-alternatives --install "/usr/bin/javac" "javac" "<Custom PATH>/bin/javac" 0

شناساندن جاوا (Web Start)

sudo update-alternatives --install "/usr/bin/javaws" "javaws" "<Custom PATH>/bin/javaws" 0

 

نکته‌مهم

 در ورژن‌های شماره ۷ یا ۸  مورد javaws یا java web start وجود داشت ولی در ورژن‌های بالاتر این مورد وجود ندارد که برای این کار با نصب بسته icedtea می‌توانیم javaws را به سیستم معرفی کنیم

sudo apt install icedtea-netx 
sudo yum install icedtea-web

در این صورت برنامه های با فرمت jnlp می‌توانیم با دستور زیر اجرا نماییم

/usr/bin/javaws /tmp/launch.jnlp 

 

مشاهده گانفیگ فعلی جاوا

java -version
sudo update-alternatives --list java
sudo update-alternatives --list javac
sudo update-alternatives --list javaws

 

 

کانفیگ کردن یک جاوای جدید

اگر هیج جاوایی در سیستم نداشته باشیم همان اولین جاوا بعنوان پیش فرض تلقی خواهد شود ولی اگر از پیش جاوا با نسخه دیگری درسیستم موجود باشد باید تنظیمات را از جاوای نسحه قبل به جاوای نسخه جدید منتقل نماییم:

sudo update-alternatives --config java
sudo update-alternatives --config javac
sudo update-alternatives --config javaws

یا به روش زیر عمل نماییم

sudo update-alternatives --set java  <PATH>
sudo update-alternatives --set javac <PATH>
sudo update-alternatives --set javaws <PATH>

 

حذف یک نسخه از جاوا

برای حذف یک نسخه از جاوا بهتر است از دستور زیر اقدام نمایید

گام اول: مشاهده نسخه ها به همراه مسیرهای آنها

java -version
sudo update-alternatives --list java
sudo update-alternatives --list javac
sudo update-alternatives --list javaws

گام دوم: حذف نسخه مورد نظر توسط ارائه مسیر آن ورژن

sudo update-alternatives --remove java <Path>
sudo update-alternatives --remove javac <Path>
sudo update-alternatives --remove javaws <Path>

example:
sudo update-alternatives --remove java /opt/java8/bin/java

گام سوم: تعیین نسخه مطلوب باقیمانده از نسخه‌های جاوا بعنوان پیش‌فرض

sudo update-alternatives --config java
sudo update-alternatives --config javac
sudo update-alternatives --config javaws

 

 

 

 

 

 

 

 

 

 

  • behrooz mohamadi nsasab
۰۲
شهریور

نصب برنامه‌های زیر:

sudo apt install tor torsocks

استفاده به دو حالت زیر:

1-Temporary:
     torsocks COMMAND 
Example:
     curl https://showip.net

 

2-Permanent over shell
     . torsocks  on
Example
     curl https://showip.net

با استفاده از هر دو روش بالا موجب خواهد شد که آی پی حقیقی شما در پس یک آی پی دیگر مخفی شود.

 

 

  • behrooz mohamadi nsasab
۱۴
اسفند

اگر جندین کارت شبکه را به جهت افزایش troughtPut و bandwidth به هم پیوند بدهیم و در نتیجه خروجی حاصله برابر جمع پهنای باندها(هریک به تنهایی) بشود در این صورت از تکنیک bond استفاده شده است:

 

 

 

modprobe bonding
ifconfig eth0 down
ifconfig eth1 down
ifconfig bond0 up
ifenslave bond0 eth0 eth1
ifconfig bond0 192.168.0.1 netmask 255.255.255.0
ifconfig eth0 up
ifconfig eth1 up
----------------------------------------
# ip link add bond0 type bond
# ip link set bond0 type bond miimon 100 mode active-backup
# ip link set em1 down
# ip link set em1 master bond0
# ip link set em2 down
# ip link set em2 master bond0
# ip link set bond0 up

URL1

URL2

URL3

  • behrooz mohamadi nsasab
۰۱
مرداد


tcpdump -i eth0 #Capture Packets from Specific Interface

tcpdump -i any #Capture all packets in any interface

tcpdump -c 5 -i eth0 #Capture Only N Number of Packets

tcpdump -A -i eth0 #Print Captured Packets in ASCII

tcpdump -D #Display Available Interfaces

tcpdump -XX -i eth0 #Display Captured Packets in HEX and 

tcpdump -w 0001.pcap -i eth0 #Capture and Save Packets in a File

tcpdump -r 0001.pcap #Read Captured Packets File

tcpdump -n #show IP address replace name (disable name resolution) 

tcpdump -nn  #show port address replace name (disable port resolution with -nn

tcpdump  tcp #Capture only TCP Packets.

tcpdump port 22 #Capture Packet from Specific Port

tcpdump port 80 #capture packets related to a web (HTTP) service

tcpdump -i eth0 src 192.168.0.2 #Capture Packets from source IP

tcpdump -i eth0 dst 50.116.66.139 #Capture Packets from destination IP

tcpdump --number #show acket numbers in output

tcpdump -t #omit timestamp info from tcpdump outpu

tcpdump -v #show detailed output

tcpdump  icmp #capture ICMP packets only

tcpdump host 54.204.39.132 #only packets related to a specific host

tcpdump -i any -c5 -nn \

     src 192.168.122.98 and port 80 #filter packets from source IP address 192.168.122.98 and service HTTP only

tcpdump -i any -c5 -nn "port 80 \

     and (src 192.168.122.98 \

     or src 54.204.39.132)" #filtering packets for HTTP service only (port 80) and source IP addresses 192.168.122.98 or 54.204.39.132



  • behrooz mohamadi nsasab
۰۸
خرداد

CLOSED: #Indicates that the server has received an ACK signal from the client and the connection is closed

CLOSE_WAIT: #[Indicates that the server has received the first FIN signal from the client and the connection is in the process of being closed]

#[So this essentially means that his is a state where socket is waiting for the application to execute close()]

#[A socket can be in CLOSE_WAIT state indefinitely until the application closes it]

#[Faulty scenarios would be like filedescriptor leak, server not being execute close() on socket leading to pile up of close_wait sockets]

ESTABLISHED: #Indicates that the server received the SYN signal from the client and the session is established

FIN_WAIT_1: #Indicates that the connection is still active but not currently being used

FIN_WAIT_2: #Indicates that the client just received acknowledgment of the first FIN signal from the server

LAST_ACK #Indicates that the server is in the process of sending its own FIN signal

LISTENING: #Indicates that the server is ready to accept a connection

SYN_RECEIVED: #Indicates that the server just received a SYN signal from the client

SYN_SEND: #Indicates that this particular connection is open and active

TIME_WAIT: #Indicates that the client recognizes the connection as still active but not currently being used

  • behrooz mohamadi nsasab
۲۳
ارديبهشت

Resolve:

systemd-resolve -t MX gmail.com   #show mail server

systemd-resolve -t SOA gmail.com   #show SOA .     Start Of Authority (More administrative information)   URL

systemd-resolve 85.214.157.7        #Get domain name

nslookup domain.ir [#Finding The IP Address of an Host from default dns server]

nslookup domain.ir 8.8.8.8[#Finding The IP Address of an Host From non default dns server]

nslookup -querytype=mx domain.ir[ #Find Mail Servers for a Domain]

nslookup -query=mx domain.ir [#Find Mail Servers]

nslookup -query=ns domain.ir [ #Find NameServers]

nslookup -query=soa domain.ir [ #display the SOA record (information about the domain]

nslookup -query=any domain.ir [ #display all the available DNS records]

host -la domain.com [Show all record with Information]

dig Domain.it axfr [Show all record with Information]

systemd-resolve --statistics          #informations

 

Flush the DNS Cache   URL

Method 1: Using systemd-resolve to flush DNS-Cache

sudo systemd-resolve --flush-caches

sudo systemd-resolve --statistics

 

Method 2: Using dns-clean to flush DNS-Cache

sudo /etc/init.d/dns-clean start

 

 

Resolve.conf

Install:

sudo apt install resolvconf

For fix and NotChange file:

vim  /etc/NetworkManager/NetworkManager.conf

#Add below to main area :

dns=none

 

  • behrooz mohamadi nsasab
۲۴
فروردين
[root@dlp ~]# yum --enablerepo=epel -y install xrdp				# install from EPEL
[root@dlp ~]# systemctl start xrdp 
[root@dlp ~]# systemctl enable xrdp 
[root@dlp ~]# firewall-cmd --add-port=3389/tcp --permanent    #If Firewalld is running, allow RDP port.
[root@dlp ~]# firewall-cmd --reload 

URL

  • behrooz mohamadi nsasab
۲۰
اسفند

  • yum install curlftpfs             [# if error: yum install fuse ]
  • $ftphost = [FTP host]
  • $mount = [Mounted to folder]
  • $user = [FTP username]
  • $pass = [FTP password]
  • curlftpfs $ftphost $mount -o user=$user:$pass,allow_other     [# Mount the CurlFtpFS]
  • fusermount -u $mount      [# Unmount the CurlFtpFS]
                          • behrooz mohamadi nsasab
                          ۱۴
                          اسفند

                           

                           

                          Show address:

                          ip: show commands:

                          • ip help                                    ---> #Display ip commands and arguments
                          • ip -4 a                                     ---> #Only show TCP/IP IPv4
                          • ip -6 a                                     ---> #Only show TCP/IP IPv6
                          • ip a list eth0                           ---> #Only show eth0 interface
                          • ip a show dev eth0                 ---> #Only show eth0 interface
                          • ip a show eth0                        ---> #Only show eth0 interface

                          addr: Display IP Addresses and property information(abbreviation of address)

                          • ip addr                                    ---> #Show information for all addresses
                          • ip addr help                            ---> #Display address commands and arguments
                          • ip addr show dev eth0            ---> #Display information only for device

                          link: Manage and display the state of all network interfaces

                          • ip link help                             ---> #Display link commands and arguments
                          • ip link ls up                            ---> #Only show running interfaces
                          • ip link show dev eth0             ---> #Display information only for device eth0
                          • ip link                                     ---> #Show information for all interfaces
                          • ip -s link                                 ---> #Display interface statistics
                          • ip -s -s link ls eth0                  ---> #get information about a particular network interface
                          • ip link set eth0 up                   ---> #Bring eth0 online
                          • ip link set eth0 down              ---> #Bring eth0 offline
                          • ip link set eth0 promisc on     ---> #Enable promiscuous mode for eth0
                           

                          Add or Delete Address:

                          • ip a add {ip_addr/mask} dev {interface}                             ---> #The syntax is as follows to add an IPv4/IPv6 address
                          • ip a del {ipv6_addr_OR_ipv4_addr} dev {interface}          ---> The syntax is as follows to remove an IPv4/IPv6 address:
                          • ip addr add 192.168.1.1/24 dev eth0                                   ---> #Add address 192.168.1.1 with netmask 24 to device eth0
                          • ip a add 192.168.1.200/255.255.255.0 dev eth0                   ---> To assign 192.168.1.200/255.255.255.0 to eth0
                          • ip a add 192.168.1.200/24 dev eth0                                     ---> To assign 192.168.1.200/255.255.255.0 to eth0
                          • ip addr del 192.168.1.1/24 dev eth0                                     ---> #Remove address 192.168.1.1/24 from device eth0
                          • ip a del 192.168.1.200/24 dev eth0                                       ---> To delete 192.168.1.200/24 from eth0

                           


                          neigh

                          neigh : ARP, Show neighbour objects; also known as the ARP table for IPv4

                          • ip neigh                                                                                    ---> #Display neighbour objects(Show neighbour objects; also known as the ARP table for IPv4)
                          • ip neigh help                                                                           ---> #Display neighbour commands and arguments
                          • ip neighbour                                                                            ---> #View the MAC address of the devices connected in your LAN
                          • ip neigh show dev eth0                                                            ---> #Show the ARP cache for device eth0
                          • ip neigh add 192.168.1.1 lladdr 1:2:3:4:5:6 dev eth0              ---> #Add address 192.168.1.1 with MAC 1:2:3:4:5:6 to eth0
                          • ip neigh del 192.168.1.1 dev eth0                                            ---> #Invalidate the entry for 192.168.1.1 on eth0
                          • ip neigh replace 192.168.1.1 lladdr 1:2:3:4:5:6 dev eth0         ---> #Replace the entry for address 192.168.1.1 to use MAC 1:2:3:4:5:6 on eth0
                          • ip n show                                                                                  ---> #Display neighbour/arp cache
                          • ip neigh show                                                                            ---> #Display neighbour/arp cache

                          Sample outputs (note: masked out some data with alphabets):

                          74.xx.yy.zz dev eth1 lladdr 00:30:48:yy:zz:ww REACHABLE

                          10.10.29.66 dev eth0 lladdr 00:30:48:c6:0a:d8 REACHABLE

                          74.ww.yyy.xxx dev eth1 lladdr 00:1a:30:yy:zz:ww REACHABLE

                          10.10.29.68 dev eth0 lladdr 00:30:48:33:bc:32 REACHABLE

                          74.fff.uu.cc dev eth1 lladdr 00:30:48:yy:zz:ww STALE

                          74.rr.ww.fff dev eth1 lladdr 00:30:48:yy:zz:ww DELAY

                          10.10.29.65 dev eth0 lladdr 00:1a:30:38:a8:00 REACHABLE

                          10.10.29.74 dev eth0 lladdr 00:30:48:8e:31:ac REACHABLE

                           

                          The last field show the the state of the “neighbour unreachability detection” machine for this entry:

                          STALE – The neighbour is valid, but is probably already unreachable, so the kernel will try to check it at the first transmission.

                          DELAY – A packet has been sent to the stale neighbour and the kernel is waiting for confirmation.

                          REACHABLE – The neighbour is valid and apparently reachable.

                           

                          Add a new ARP entry:

                          • ip neigh add {IP-HERE} lladdr {MAC/LLADDRESS} dev {DEVICE} nud {STATE}     ---> #syntax is
                          • ip neigh add 192.168.1.5 lladdr 00:1a:30:38:a8:00 dev eth0 nud perm         ---> #add a permanent ARP entry for the neighbour 192.168.1.5 on the device eth0:

                          neighbour state (nud):

                          permanent The neighbour entry is valid forever and can be only be removed administratively

                          noarp The neighbour entry is valid. No attempts to validate this entry will be made but it can be removed when its lifetime expires.

                          stale The neighbour entry is valid but suspicious. This option to ip neigh does not change the neighbour state if it was valid and the address is not changed by this command.

                          reachable The neighbour entry is valid until the reachability timeout expires.

                          Delete a ARP entry:

                          • ip neigh del {IPAddress} dev {DEVICE}               ---> #Syntax
                          • ip neigh del 192.168.1.5 dev eth1                            ---> #invalidate or delete an ARP entry for the neighbour 192.168.1.5 on the device eth0

                          Change ARP state:

                           

                          • ip neigh chg 192.168.1.100 dev eth1 nud reachable ---> #TO REACHABLE FOR THE NEIGHBOUR 192.168.1.100 ON THE DEVICE ETH1:


                           


                          Route

                          Route:Display and alter the routing table

                          • ip route                                                                      ---> #List all of the route entries in the kernel[routing tables]
                          • ip route show                                                            ---> #check the routing table information of the system
                          • ip route add default via 192.168.1.1 dev eth0          ---> #Add a default route (for all addresses) via the local gateway 192.168.1.1 that can be reached on device eth0
                          • ip route add 192.168.1.0/24 via 192.168.1.1            ---> #Add a route to 192.168.1.0/24 via the gateway at 192.168.1.1
                          • ip route add 192.168.1.0/24 dev eth0                       ---> #Add a route to 192.168.1.0/24 that can be reached on device eth0
                          • ip route del default via 192.168.1.1                          ---> #delete default gateway                                     
                          • ip route delete 192.168.1.0/24 via 192.168.1.1        ---> #Delete the route for 192.168.1.0/24 via the gateway at 192.168.1.1
                          • ip route replace 192.168.1.0/24 dev eth0                  ---> #Replace the defined route for 192.168.1.0/24 to use device eth0
                          • ip route get 192.168.1.5                                            ---> #Display the route taken for IP 192.168.1.5
                          • ip r                                                                             ---> #display the contents of the routing tables
                          • ip r list                                                                       ---> #display the contents of the routing tables
                          • ip route list                                                                ---> #display the contents of the routing tables
                          • ip r list 192.168.1.0/24                                              ---> #Display routing for 192.168.1.0/24

                          output:192.168.1.0/24 dev eth1  proto kernel  scope link  src 192.168.1.10

                           

                          Add a new route:

                          • ip route add {NETWORK/MASK} via {GATEWAYIP}               ---> #The syntax is
                          • ip route add {NETWORK/MASK} dev {DEVICE}                      ---> #The syntax is
                          • ip route add default {NETWORK/MASK} dev {DEVICE}          ---> #The syntax is
                          • ip route add default {NETWORK/MASK} via {GATEWAYIP}   ---> #The syntax is
                          • ip route add 192.168.1.0/24 via 192.168.1.254                               ---> #Add a plain route to network 192.168.1.0/24 via gateway 192.168.1.254
                          • ip route add 192.168.1.0/24 dev eth0                                              ---> #To route all traffic via 192.168.1.254 gateway connected via eth0 network interface

                          Delete a route:

                          • ip route del default                                                                           ---> #The syntax is[as follows to delete default gateway]
                          • ip route del 192.168.1.0/24 dev eth0                                                ---> #In this example, delete the route created in previous subsection:

                           


                          Disable [or] flush:

                          This flush or f command flushes neighbour/arp tables, by specifying some condition.

                          • ip -s -s n f {IPAddress}                   ---> #The syntax is
                          • ip -s -s n f 192.168.1.5                    ---> #In this example, flush neighbour/arp table
                          • ip -s -s n flush 192.168.1.5             ---> #In this example, flush neighbour/arp table
                          • ip -4 addr flush label "ppp*"           ---> #disable IP address on all the ppp (Point-to-Point) interfaces
                          • ip -4 addr flush label "eth*"            ---> #Here is another example for all the Ethernet interfaces
                          • ip -s -s a f to 192.168.2.0/24           --->  #Delete all the IP addresses from the private network (For example) 192.168.2.0/24

                          output:

                          2: eth0    inet 192.168.2.201/24 scope global secondary eth0

                          2: eth0    inet 192.168.2.200/24 scope global eth0

                          *** Round 1, deleting 2 addresses ***

                          *** Flush is complete after 1 round ***

                           


                          Txqueuelen

                          set the length of the transmit queue of the device using  ip command as follows:

                          • ip link set txqueuelen {NUMBER} dev {DEVICE}    --->   # Syntax
                          • ip link set txqueuelen 10000 dev eth0                           ---> #change the default txqueuelen from 1000 to 10000 for the eth0
                          • ip a list eth0

                           


                          MTU

                          For gigabit networks, set maximum transmission units (MTU) sizes (JumboFrames) for better network performance. The syntax is:
                          • ip link set mtu {NUMBER} dev {DEVICE}          ---> #Syntax
                          • ip link set eth0 mtu 9000                                         ---> #Set the MTU on eth0 to 9000
                          • ip link set mtu 9000 dev eth0                                   ---> #To change the MTU of the device eth0 to 9000
                          • ip a list eth0

                          Sample outputs:

                          2: eth0:  mtu 9000 qdisc pfifo_fast state UP qlen 1000

                              link/ether 00:08:9b:c4:30:30 brd ff:ff:ff:ff:ff:ff

                              inet 192.168.1.10/24 brd 192.168.1.255 scope global eth1

                              inet6 fe80::208:9bff:fec4:3030/64 scope link 

                                 valid_lft forever preferred_lft forever


                           


                          Broadcast:

                          Notice:By default, the ip command does not set any broadcast address unless explicitly requested

                          • ip addr add brd {ADDDRESS-HERE} dev {interface}          ---> #ADDING THE BROADCAST ADDRESS ON THE INTERFACE
                          • ip addr add broadcast {ADDDRESS-HERE} dev {interface} ---> #ADDING THE BROADCAST ADDRESS ON THE INTERFACE
                          • ip addr add broadcast 172.20.10.255 dev eth0                           ---> #add 172.20.10.255 as broadcast on eth0
                           

                          Multicast

                           

                          maddr: Manage and display multicast IP addresses

                          • ip maddr                                   ---> #Display multicast information for all devices
                          • ip maddr show dev eth0           ---> #Display multicast information for device eth0


                           

                          OLD and NEW Commands:

                          • arp -a                                                      -----> ip neigh
                          • arp -v                                                      -----> ip -s neigh
                          • arp -s 192.168.1.1 1:2:3:4:5:6                -----> ip neigh add 192.168.1.1 lladdr 1:2:3:4:5:6 dev eth1
                          • arp -i eth1 -d 192.168.1.1                       -----> ip neigh del 192.168.1.1 dev eth1
                          • ifconfig -a                                               -----> ip addr
                          • ifconfig eth0 down                                 -----> ip link set eth0 down
                          • ifconfig eth0 up                                      -----> ip link set eth0 up
                          • ifconfig eth0 192.168.1.1                       -----> ip addr add 192.168.1.1/24 dev eth0
                          • ifconfig eth0 netmask 255.255.255.0     -----> ip addr add 192.168.1.1/24 dev eth0
                          • ifconfig eth0 mtu 9000                           -----> ip link set eth0 mtu 9000
                          • ifconfig eth0:0 192.168.1.2                    -----> ip addr add 192.168.1.2/24 dev eth0
                          • netstat -g                                                 -----> ip maddr
                          • route                                                        -----> ip route
                          • route add -net 192.168.1.0 netmask 255.255.255.0 dev eth0              -----> ip route add 192.168.1.0/24 dev eth0
                          • route add default gw 192.168.1.1                                                        -----> ip route add default via 192.168.1.1
                           

                          Abbreviation:

                          Object Abbreviated form Purpose
                          • link(l)                               ----> Network device.
                          • address(a [or] addr)         ----> Protocol (IP or IPv6) address on a device.
                          • addrlabel(addrl)               ----> Label configuration for protocol address selection.
                          • neighbour(n [or] neigh)   ----> ARP or NDISC cache entry.
                          • route(r)                             ----> Routing table entry.
                          • rule(ru)                             ----> Rule in routing policy database.
                          • maddress(m [or] maddr)  ----> Multicast address.
                          • mroute(mr)                       ----> Multicast routing cache entry.
                          • tunnel(t)                            ----> Tunnel over IP.
                          • xfrm(x)                              ----> Framework for IPsec protocol.


                          URL1

                          • behrooz mohamadi nsasab
                          ۱۳
                          اسفند

                          1-show gateway(s):

                           

                          • route
                          • route -n
                          • ip route show
                          • ip route list

                           

                          Add route:

                           

                          • route add default gw {IP-ADDRESS(router IP)} {INTERFACE-NAME}
                          • route add default gw 192.168.1.254 eth0                            #Route all traffic via 192.168.1.254 gateway connected via eth0 network interface:
                          • ip route add 192.168.1.0/24 dev eth0                                        #to route all traffic via 192.168.1.254 gateway connected via eth0 network interface:
                          • ip route add 192.168.1.0/24 via 192.168.1.254                         #to route all traffic via 192.168.1.254 gateway connected via eth0 network interface:

                          Delete rout

                          • ip route del default via 192.168.122.1 dev eth0
                           

                          GUI(set configuration from ui)

                           

                          • redhat-config-network                            #if your are using Red Hat/CentOS/Fedora core Linux type this
                          • network-admin #If you are using other Linux distribution use this
                          • behrooz mohamadi nsasab
                          ۱۱
                          اسفند

                          سوکت‌های فعلی سرور که به هیچ فایلی از هارد وصل نشده است - پردازه‌های موجود در رم که ممکن است ویروس باشند

                          lsof +L1

                          • behrooz mohamadi nsasab
                          ۳۰
                          بهمن

                          برای راه اندازی وی پی ان از طریق terminal در لینوکس به روش زیر عمل مینماییم

                          modprobe nf_conntrack_pptp    # add pptp module to kernel
                          pppd call linuxconfig     # stablished Tunnel
                          route add default dev ppp0    #route all traffic to Tunnel

                          اسکریپت شده دستورات بالا:

                          #!/bin/bash
                          username=$1;
                          password=$2;
                          if [[ "$username" != "" && "$password" != "" ]]; then
                          echo "INSTALL STARTING ..."
                          # rpm -ivh pptp-1.7.2-22.el7.x86_64.rpm    #if is not install in server please install it
                          modprobe  nf_conntrack_pptp
                          echo "$username   PPTP    $password        *">/etc/ppp/pap-secrets
                          echo 'pty "pptp 10.10.10.10 --nolaunchpppd"    #10.10.10.10 Is Gateway's ip
                          name '$username'
                          remotename PPTP
                          #require-mppe-128
                          file /etc/ppp/options.pptp
                          ipparam linuxconfig'>/etc/ppp/peers/linuxconfig
                          echo 'lock
                          noauth
                          refuse-eap
                          refuse-chap
                          refuse-mschap
                          nobsdcomp
                          nodeflate'>/etc/ppp/options.pptp  #or comment refuse-pap line in tis file
                          pppd call linuxconfig
                          route add default dev ppp0
                          else
                          echo "please insert username password."
                          fi



                          نکته: یکی از dependency های اسکریپت بالا URL

                          دستورات بالا با دوفایل ارتباط دارد که این فایل‌ها وقتی بخواهیم بدون اسکریپت بالا پیکربندی کنیم به صورت زیر عمل خواهیم کرد.


                          vim /etc/ppp/peers/linuxconfig

                          pty "pptp 10.10.10.10 --nolaunchpppd" 
                          name USERNAME
                          remotename PPTP
                          #require-mppe-128
                          file /etc/ppp/options.pptp
                          ipparam linuxconfig


                          vim /etc/ppp/pap-secret

                          # Secrets for  authentication using PAP
                          # client server secret      IP addresses
                          username     PPTP    password     *

                          • behrooz mohamadi nsasab
                          ۱۰
                          بهمن

                          یک تجربه: در دبیان ۹ برای اینکه firmware کارت شبکه یو اس بی رو بشناسانیم از روش زیر استفاده میکنیم



                          add to /etc/apt/source.list
                          deb http://ftp.fr.debian.org/debian jessie main contrib non-free
                          deb http://httpredir.debian.org/debian/ stretch main contrib non-free

                          sudo apt-get install debian-reference
                          apt-get update && apt-get install firmware-iwlwifi
                          sudo apt-get update && apt-get install firmware-iwlwifi
                          sudo apt-get update && sudo apt-get install firmware-iwlwifi
                          sudo apt-get install modplug-tools 
                          sudo apt-get install modprobe
                          sudo apt-get install modprob
                          sudo apt-get install kmod
                          sudo apt-get install wicd
                          sudo  apt-get install firmware-realtek
                          sudo  apt-get install firmware-iwlwifi 
                          sudo  apt-get install firmware-linux
                          sudo  apt-get install amd64-microcode firmware-linux-nonfree firmware-misc-nonfree

                          • behrooz mohamadi nsasab
                          ۱۰
                          بهمن
                          توسط این برنامه می‌توان فایل یا متن از طریق شبکه منتقل نمود:

                          ۱-ارسال متن:

                          در گیرنده دستور زیر زده شود:
                          nc -l -p PortNumber
                          در سمت فرستنده نیز دستور زیر زده شود:
                          echo "TEXT" | netcat  [Destination] PortNumber

                          2-ارسال فایل:

                          درسمت گیرنده دستور زیر زده شود
                          nc -l -p 1234 > out.file
                          در سمت فرستنده نیز دستور زیر زده شود
                          nc -w 3 [destination] 1234 < out.file


                          3-ارسال فایل-فشرده سازی

                          درسمت فرستنده دستور زیر زده شود
                          tar cfp - /some/dir | compress -c | nc -w 3 [destination] 1234
                          در سمت گیرنده نیز دستور زیر زده شود
                          nc -l -p 1234 | uncompress -c | tar xvfp -


                          4-ارسال فایل- محتویات یک هارد (پارتیشن)

                          درسمت فرستنده دستور زیر زده شود
                          dd if=/dev/hda3 | gzip -9 | nc -l 3333
                          در سمت گیرنده نیز دستور زیر زده شود
                          nc [destination] 3333 | pv -b > hdImage.img.gz



                          • behrooz mohamadi nsasab
                          ۰۳
                          تیر
                          در لینوکس استفاده از پورت های کمتر از 1024 برای کاربران عادی مجاز نمیباشد، در چنین حالتی مثلا ما اگر بخواهیم سامانه خود را روی پورت 80 بالا بیاوریم که پورت پیش فرض وب میباشد، ناچاریم با استفاده از sudo این کار را بکنیم که ایرادات و مشکلات خاص خود را دارد.

                          authbind ابزاری میباشد که به ما اجازه میدهد پورت های خاصی را برای کاربران خاص باز کنیم.

                          در توضیح مرحله به مرحله زیر فرض ما این است که میخواهیم پورت 80 را برای کاربری به نام user باز کنیم:

                          1- ابتدا به پوشه /etc/default/ رفته و یک فایل به نام کاربر مورد نظر ایجاد میکنیم:
                          cd /etc/default
                          sudo vim user
                          2- در درون فایل user مقدار زیر را مینویسیم
                          AUTHBIND=yes

                           3- ابزار authbind را نصب میکنیم:
                          sudo apt-get install authbind
                          4- دستورات زیر را اجرا میکنیم:
                          sudo touch /etc/authbind/byport/80
                          sudo chmod 755 /etc/authbind/byport/80
                          sudo chown user:user /etc/authbind/byport/80
                          • behrooz mohamadi nsasab
                          ۲۴
                          خرداد

                          نصب در کلاینت

                          در سمت کلایت باید سرویس NTP را نصب نمایید:
                          sudo apt-get install ntp
                          sudo yum install ntp

                          بعد از نصب در فایل مسیر زیر آدرس سرور را مشخص نمایید:
                          sudo vim /etc/ntp.conf
                           
                          server 0.debian.pool.ntp.org iburst
                          server 1.debian.pool.ntp.org iburst
                          server 2.debian.pool.ntp.org iburst
                          server 3.debian.pool.ntp.org iburst
                          نکته: عبارت iburst را در مقابل سرور قرار بدهید تا این که شدت کوئری زدن به سرور افزایش یابد (حتی در صورتی که امکان sync شدن برقرا نیست بصورت force عمل sync صورت گیرد)

                          بعد از این که تنظیمات انجام  شد سرویس را ریست نمایید:
                          sudo /etc/init.d/ntpd restart
                           

                          تست کارکرد سرویس

                          از دستور زیر برای مشاهده کارایی استفاده می‌کنیم:
                          $ ntpq -pn
                               remote           refid      st t when poll reach   delay   offset  jitter
                          ==============================================================================
                          *198.60.22.240   .GPS.            1 u  912 1024  377    0.488   -0.016   0.098
                          +199.104.120.73  .GPS.            1 u   88 1024  377    0.966    0.014   1.379
                          -155.98.64.225   .GPS.            1 u   74 1024  377    2.782    0.296   0.158
                          -137.190.2.4     .GPS.            1 u 1020 1024  377    5.248    0.194   0.371
                          -131.188.3.221   .DCFp.           1 u  952 1024  377  147.806   -3.160   0.198
                          -217.34.142.19   .LFa.            1 u  885 1024  377  161.499   -8.044   5.839
                          -184.22.153.11   .WWVB.           1 u  167 1024  377   65.175   -8.151   0.131
                          +216.218.192.202 .CDMA.           1 u   66 1024  377   39.293    0.003   0.121
                          -64.147.116.229  .ACTS.           1 u   62 1024  377   16.606    4.206   0.216

                          توضیحات  موارد بالا

                              remote- The remote server you wish to synchronize your clock with
                              refid- The upstream stratum to the remote server. For stratum 1 servers, this will be the stratum 0 source.
                              st- The stratum level, 0 through 16.
                              t- The type of connection. Can be "u" for unicast or manycast, "b" for broadcast or multicast, "l" for local reference clock, "s" for symmetric peer, "A" for a manycast server, "B" for a broadcast server, or "M" for a multicast server
                              when- The last time when the server was queried for the time. Default is seconds, or "m" will be displayed for minutes, "h" for hours and "d" for days.
                              poll- How often the server is queried for the time, with a minimum of 16 seconds to a maximum of 36 hours. It's also displayed as a value from a power of two. Typically, it's between 64 seconds and 1024 seconds.
                              reach- This is an 8-bit left shift octal value that shows the success and failure rate of communicating with the remote server. Success means the bit is set, failure means the bit is not set. 377 is the highest value.
                              delay- This value is displayed in milliseconds, and shows the round trip time (RTT) of your computer communicating with the remote server.
                              offset- This value is displayed in milliseconds, using root mean squares, and shows how far off your clock is from the reported time the server gave you. It can be positive or negative.
                              jitter- This number is an absolute value in milliseconds, showing the root mean squared deviation of your offsets.

                           

                          علامت‌های کناری در remote server:

                          • Next to the remote server, you'll notice a single character. This character is referred to as the "tally code", and indicates whether or not NTP is or will be using that remote server in order to synchronize your clock. Here are the possible values
                          • " " Discarded as not valid. Could be that you cannot communicate with the remote machine (it's not online), this time source is a ".LOCL." refid time source, it's a high stratum server, or the remote server is using this computer as an NTP server.
                              "x" Discarded by the intersection algorithm.
                              "." Discarded by table overflow (not used).
                              "-" Discarded by the cluster algorithm.
                              "+" Included in the combine algorithm. This is a good candidate if the current server we are synchronizing with is discarded for any reason.
                              "#" Good remote server to be used as an alternative backup. This is only shown if you have more than 10 remote servers.
                              "*" The current system peer. The computer is using this remote server as its time source to synchronize the clock
                              "o" Pulse per second (PPS) peer. This is generally used with GPS time sources, although any time source delivering a PPS will do. This tally code and the previous tally code "*" will not be displayed simultaneously.
                           

                          توضیحات ستون refid:


                               IP address- The IP address of the remote peer or server.
                              .ACST.- NTP manycast server.
                              .ACTS.- Automated Computer Time Service clock reference from the American National Institute of Standards and Technology.
                              .AUTH.- Authentication error.
                              .AUTO.- Autokey sequence error.
                              .BCST.- NTP broadcast server.
                              .CHU.- Shortwave radio receiver from station CHU operating out of Ottawa, Ontario, Canada.
                              .CRYPT.- Autokey protocol error
                              .DCFx.- LF radio receiver from station DCF77 operating out of Mainflingen, Germany.
                              .DENY.- Access denied by server.
                              .GAL.- European Galileo satellite receiver.
                              .GOES.- American Geostationary Operational Environmental Satellite receiver.
                              .GPS.- American Global Positioning System receiver.
                              .HBG.- LF radio receiver from station HBG operating out of Prangins, Switzerland.
                              .INIT.- Peer association initialized.
                              .IRIG.- Inter Range Instrumentation Group time code.
                              .JJY.- LF radio receiver from station JJY operating out of Mount Otakadoya, near Fukushima, and also on Mount Hagane, located on Kyushu Island, Japan.
                              .LFx.- Generic LF radio receiver.
                              .LOCL.- The local clock on the host.
                              .LORC.- LF radio receiver from Long Range Navigation (LORAN-C) radio beacons.
                              .MCST.- NTP multicast server.
                              .MSF.- National clock reference from Anthorn Radio Station near Anthorn, Cumbria.
                              .NIST.- American National Institute of Standards and Technology clock reference.
                              .PPS.- Pulse per second clock discipline.
                              .PTB.- Physikalisch-Technische Bundesanstalt clock reference operating out of Brunswick and Berlin, Germany.
                              .RATE.- NTP polling rate exceeded.
                              .STEP.- NTP step time change. The offset is less than 1000 millisecends but more than 125 milliseconds.
                              .TDF.- LF radio receiver from station TéléDiffusion de France operating out of Allouis, France.
                              .TIME.- NTP association timeout.
                              .USNO.- United States Naval Observatory clock reference.
                              .WWV.- HF radio receiver from station WWV operating out of Fort Collins, Colorado, United States.
                              .WWVB.- LF radio receiver from station WWVB operating out of Fort Collins, Colorado, United States.
                              .WWVH.- HF radio receiver from station WWVH operating out of Kekaha, on the island of Kauai in the state of Hawaii, United States.

                          دستوری برای چک شدن این که سرور در چه وضعیتی قرار دارد:
                          sudo yum install ntp

                          $ ntpq -c peer -c as -c rl
                               remote           refid      st t when poll reach   delay   offset  jitter
                          ==============================================================================
                           .               10.200.108.62    2 u   20   64    1    0.537    1.660   0.000
                           .               .INIT.          16 u    -   64    0    0.000    0.000   0.000


                          ind assid status  conf reach auth condition  last_event cnt
                          ===========================================================
                            1 15488  9024   yes   yes  none    reject   reachable  2
                            2 15489  8011   yes    no  none    reject    mobilize  1
                           
                          associd=0 status=c012 leap_alarm, sync_unspec, 1 event, freq_set,
                          version="ntpd 4.2.6p5@1.2349-o Fri Jul 22 17:30:51 UTC 2016 (1)",
                          processor="x86_64", system="Linux/3.16.0-4-amd64", leap=11, stratum=16,
                          precision=-23, rootdelay=0.000, rootdisp=0.300, refid=INIT,
                          reftime=00000000.00000000  Mon, Jan  1 1900  3:25:44.000,
                          clock=dd970af2.38da6724  Sun, Oct 22 2017 15:47:54.222, peer=0, tc=3,
                          mintc=3, offset=0.000, frequency=5.387, sys_jitter=0.000,
                          clk_jitter=0.000, clk_wander=0.000
                          در دستور بالا عبارت last_event اهمیت دارد که آبا سرور در دسترس قرار دارد یا خیر و این که در ستون reach عبارت yes هست یا no (yes یعنی از سرور مورد نظر در حال گرفتن دیتا است)
                          تست دیگری که در سمت کلاینت اطلاعات مفیدی به کاربر میدهد
                          $ ntpq
                          ntpq> as
                          ind assid status  conf reach auth condition  last_event cnt
                          ===========================================================
                            1 45592  9444   yes   yes  none candidate   reachable  4
                            2 45593  962a   yes   yes  none  sys.peer    sys_peer  2
                            3 45594  9414   yes   yes  none candidate   reachable  1

                          ntpq> exit
                          $
                          لینک های مفید:

                          LINK


                          • behrooz mohamadi nsasab
                          ۲۴
                          خرداد

                          sudo vim /etc/ntp.conf

                          # /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help
                          driftfile /var/lib/ntp/ntp.drift
                          # Enable this if you want statistics to be logged.
                          #statsdir /var/log/ntpstats/
                          statistics loopstats peerstats clockstats
                          filegen loopstats file loopstats type day enable
                          filegen peerstats file peerstats type day enable
                          filegen clockstats file clockstats type day enable
                          # You do need to talk to an NTP server or two (or three).
                          #server ntp.your-provider.example
                          # pool.ntp.org maps to about 1000 low-stratum NTP servers.  Your server will
                          # pick a different set every time it starts up.  Please consider joining the
                          # pool: <http://www.pool.ntp.org/join.html>
                          server 0.debian.pool.ntp.org iburst
                          server 1.debian.pool.ntp.org iburst
                          server 2.debian.pool.ntp.org iburst
                          server 3.debian.pool.ntp.org iburst
                          # Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for
                          # details.  The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>
                          # might also be helpful.
                          #
                          # Note that "restrict" applies to both servers and clients, so a configuration
                          # that might be intended to block requests from certain clients could also end
                          # up blocking replies from your own upstream servers.
                          # By default, exchange time with everybody, but don't allow configuration.
                          ##restrict -4 default kod notrap nomodify nopeer noquery
                          ##restrict -6 default kod notrap nomodify nopeer noquery
                          # Local users may interrogate the ntp server more closely.
                          restrict 127.0.0.1
                          restrict ::1
                          #restrict 192.168.0.0 mask 255.255.252.0
                          # Clients from this (example!) subnet have unlimited access, but only if
                          # cryptographically authenticated.
                          #restrict 192.168.123.0 mask 255.255.255.0 notrust
                          # If you want to provide time to your local subnet, change the next line.
                          # (Again, the address is an example only.)
                          #broadcast 192.168.123.255
                          # If you want to listen to time broadcasts on your local subnet, de-comment the
                          # next lines.  Please do this only if you trust everybody on the network!
                          #disable auth
                          #broadcastclient


                          کانفیگ‌های موحود همانند server که در فایل ntp.conf اعمال میشوند
                          server address [key key | autokey] [burst] [iburst] [version version] [prefer] [minpoll minpoll] [maxpoll maxpoll]
                          peer address [key key | autokey] [version version] [prefer] [minpoll minpoll] [maxpoll maxpoll]
                          broadcast address [key key | autokey] [version version] [minpoll minpoll] [ttl ttl]
                          manycastclient address [key key | autokey] [version version] [minpoll minpoll [maxpoll maxpoll] [ttl ttl]

                          server:
                          For type s and r addresses, this command mobilizes a persistent client mode association with the specified remote server or local radio clock. In this mode the local clock can synchronized to the remote server, but the remote server can never be synchronized to the local clock. This command should NOT be used for type b or m addresses.

                          peer:

                          For type s addresses (only), this command mobilizes a persistent symmetric-active mode association with the specified remote peer. In this mode the local clock can be synchronized to the remote peer or the remote peer can be synchronized to the local clock. This is useful in a network of servers where, depending on various failure scenarios, either the local or remote peer may be the better source of time. This command should NOT be used for type b, m or r addresses.

                          broadcast:
                          For type b and m addresses (only), this command mobilizes a persistent broadcast mode association. Multiple commands can be used to specify multiple local broadcast interfaces (subnets) and/or multiple multicast groups. Note that local broadcast messages go only to the interface associated with the subnet specified, but multicast messages go to all interfaces.In broadcast mode the local server sends periodic broadcast messages to a client population at the address specified, which is usually the broadcast address on (one of) the local network(s) or a multicast address assigned to NTP. The IANA has assigned the multicast group address 224.0.1.1 exclusively to NTP, but other nonconflicting addresses can be used to contain the messages within administrative boundaries. Ordinarily, this specification applies only to the local server operating as a sender; for operation as a broadcast client, see the broadcastclient or multicastclient commands below.
                              
                          manycastclient:
                          For type m addresses (only), this command mobilizes a manycast client mode association for the multicast address specified. In this case a specific address must be supplied which matches the address used on the manycastserver command for the designated manycast servers. The NTP multicast address 224.0.1.1 assigned by the IANA should NOT be used, unless specific means are taken to avoid spraying large areas of the Internet with these messages and causing a possibly massive implosion of replies at the sender.The manycast command specifies that the local server is to operate in client mode with the remote servers that are discovered as the result of broadcast/multicast messages. The client broadcasts a request message to the group address associated with the specified address and specifically enabled servers respond to these messages. The client selects the servers providing the best time and continues as with the server command. The remaining servers are discarded as if never heard.

                          Options

                          autokey
                          All packets sent to and received from the server or peer are to include authentication fields encrypted using the autokey scheme described in the Authentication Options page.

                          burst
                          when the server is reachable and at each poll interval, send a burst of eight packets instead of the usual one packet. The spacing between the first and the second packets is about 16s to allow a modem call to complete, while the spacing between the remaining packets is about 2s. This is designed to improve timekeeping quality with the server command and s addresses.

                          iburst
                          When the server is unreachable and at each poll interval, send a burst of eight packets instead of the usual one. As long as the server is unreachable, the spacing between packets is about 16s to allow a modem call to complete. Once the server is reachable, the spacing between packets is about 2s. This is designed to speed the initial synchronization acquisition with the server command and s addresses and when ntpd is started with the -q option.

                          key key
                          All packets sent to and received from the server or peer are to include authentication fields encrypted using the specified key identifier with values from 1 to 65534, inclusive. The default is to include no encryption field.

                          minpoll minpoll
                          These options specify the minimum and maximum poll intervals for NTP messages, in seconds to the power of two. The maximum poll interval defaults to 10 (1,024 s), but can be increased by the maxpoll option to an upper limit of 17 (36.4 h). The minimum   poll interval defaults to 6 (64 s), but can be decreased by the minpoll option to a lower limit of 4 (16 s).

                          prefer
                          Marks the server as preferred. All other things being equal, this host will be chosen for synchronization among a set of correctly operating hosts. See the Mitigation Rules and the prefer Keyword page for further information.

                          ttl ttl
                          This option is used only with broadcast server and manycast client modes. It specifies the time-to-live ttl to use on broadcast server and multicast server and the maximum ttl for the expanding ring search with manycast client packets. Selection of the proper value, which defaults to 127, is something of a black art and should be coordinated with the network administrator.

                          version version
                          Specifies the version number to be used for outgoing NTP packets. Versions 1-4 are the choices, with version 4 the default.

                           

                          اعمال محدودیت

                          تنظبمات موجود در سرور NTP را بصورت پیش فرض تغییر ندهید تا این که به هر سرور در هرکجا بتواند سرویس بدهد. اما اگر گاهی لازم شد تا به یک دامنه ای نخواهید سرویس بدهید از عبارت restricted برای محدود شدن آن آی پی استفاده نمایید.

                          # Hosts on local network are less restricted.
                          #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

                              ignore — All packets will be ignored, including ntpq and ntpdc queries.
                              kod — a “Kiss-o'-death” packet is to be sent to reduce unwanted queries.
                              limited — do not respond to time service requests if the packet violates the rate limit default values or those specified by the discard command. ntpq and ntpdc queries are not affected. For more information on the discard command and the default values, see Section 22.16.2, “Configure Rate Limiting Access to an NTP Service”.
                              lowpriotrap — traps set by matching hosts to be low priority.
                              nomodify — prevents any changes to the configuration.
                              noquery — prevents ntpq and ntpdc queries, but not time queries, from being answered.
                              nopeer — prevents a peer association being formed.
                              noserve — deny all packets except ntpq and ntpdc queries.
                              notrap — prevents ntpdc control message protocol traps.
                              notrust — deny packets that are not cryptographically authenticated.
                              ntpport — modify the match algorithm to only apply the restriction if the source port is the standard NTP UDP port 123.
                              version — deny packets that do not match the current NTP version.


                          • behrooz mohamadi nsasab
                          ۱۹
                          خرداد
                          • 1. List Established Connections

                            By default if we run the ss command with no further options specified it will display a list of open non-listening sockets that have established connections, so for example TCP, UDP or UNIX sockets.

                            [root@centos7 ~]# ss | head -n 5
                            Netid  State      Recv-Q Send-Q Local Address:Port      Peer Address:Port
                            u_str  ESTAB      0      0       * 23740                * 23739
                            u_str  ESTAB      0      0       * 23707                * 23706
                            u_str  ESTAB      0      0       * 87021                * 88383
                            u_str  ESTAB      0      0       * 17056                * 17112
                            

                            In the above example I have limited the output, on my server I have over 500 lines printed out by running the ss command, so you may wish to pipe it into something like less to easily read it, or otherwise append additional options on the end to only show what you’re after.

                          • 2. Show Listening Sockets

                            Rather than listing all sockets, we can use the -l option to specifically list the sockets that are currently listening for a connection.

                            [root@centos7 ~]# ss -lt
                            State       Recv-Q Send-Q  Local Address:Port                Peer Address:Port
                            LISTEN      0      2                   *:kerberos-adm        *:*
                            LISTEN      0      128                 *:sunrpc              *:*
                            LISTEN      0      5                   *:kpasswd             *:*
                            LISTEN      0      10       192.168.1.14:domain              *:*
                            LISTEN      0      10          127.0.0.1:domain              *:*
                            LISTEN      0      5       192.168.122.1:domain              *:*
                            LISTEN      0      128                 *:ssh                 *:*
                            

                            In this example we have also used the -t option to only list TCP, more on this later. In future examples you will see that we will combine multiple options like this in order to quickly filter down to what we’re after.

                          • 3. Show Processes

                            We can print out the process or PID number that owns a socket with the -p option.

                            [root@centos7 ~]# ss -pl
                            Netid  State      Recv-Q Send-Q Local Address:Port     Peer Address:Port
                            tcp    LISTEN     0      128    :::http                :::*                 users:(("httpd",pid=10522,fd=4),("httpd",pid=10521,fd=4),("httpd",pid=10520,fd=4),("httpd",pid=10519,fd=4),("httpd",pid=10518,fd=4),("httpd",pid=10516,fd=4))
                            

                            In the above example I have only listed a single result, without any further options the full output of ss prints out over 500 lines to stdout. Regardless, we can see the process ID’s of the various Apache processes that are running on this server.

                          • 4. Don’t Resolve Service Names

                            By default ss will only resolve port numbers as we have previously seen, for example in the line below we can see 192.168.1.14:ssh where ssh is listed as the local port.

                            [root@centos7 ~]# ss
                            Netid  State      Recv-Q Send-Q Local Address:Port    Peer Address:Port
                            tcp    ESTAB      0      64     192.168.1.14:ssh      192.168.1.191:57091
                            

                            However if we specify the -n option, this resolution will not take place and we will instead see the port number rather than the service name.

                            [root@centos7 ~]# ss -n
                            Netid  State      Recv-Q Send-Q Local Address:Port    Peer Address:Port
                            tcp    ESTAB      0      0      192.168.1.14:22       192.168.1.191:57091
                            

                            Note that :22 is now displayed rather than :ssh as we have disabled all name resolution of hostnames and ports. You can check the /etc/services file to see a full list of which ports map to which services.

                          • 5. Resolve Numeric Address/Ports

                            We can also do the opposite of this and resolve both the IP address and port number with the -r option. With this we now see the hostname of the 192.168.1.14 server listed.

                            [root@centos7 ~]# ss -r
                            Netid  State      Recv-Q Send-Q Local Address:Port         Peer Address:Port
                            tcp    ESTAB      0      64     centos7.example.com:ssh    192.168.1.191:57091
                            
                          • 6. IPv4 Sockets

                            We can use the -4 option to only display information corresponding to IPv4 sockets. In the below example we also make use of the -l option to list everything listening on an IPv4 address.

                            [root@centos7 ~]# ss -l4
                            Netid  State      Recv-Q Send-Q     Local Address:Port        Peer Address:Port
                            udp    UNCONN     0      0              127.0.0.1:323         *:*
                            udp    UNCONN     0      0          192.168.122.1:domain      *:*
                            udp    UNCONN     0      0               *%virbr0:bootps      *:*
                            udp    UNCONN     0      0                      *:bootpc      *:*
                            tcp    LISTEN     0      128                    *:sunrpc      *:*
                            tcp    LISTEN     0      5          192.168.122.1:domain      *:*
                            tcp    LISTEN     0      128                    *:ssh         *:*
                            tcp    LISTEN     0      128            127.0.0.1:ipp         *:*
                            tcp    LISTEN     0      100            127.0.0.1:smtp        *:*
                            
                          • 7. IPv6 Sockets

                            Likewise, we can use the -6 option to only display information related to IPv6 sockets. In the below example we also make use of the -l option to list everything listening on an IPv6 address.

                            [root@centos7 ~]# ss -l6
                            Netid  State      Recv-Q Send-Q     Local Address:Port          Peer Address:Port
                            udp    UNCONN     0      0                     :::ipv6-icmp     :::*
                            udp    UNCONN     0      0                     :::22834         :::*
                            udp    UNCONN     0      0                    ::1:323           :::*
                            tcp    LISTEN     0      128                   :::sunrpc        :::*
                            tcp    LISTEN     0      128                   :::http          :::*
                            tcp    LISTEN     0      128                   :::ssh           :::*
                            tcp    LISTEN     0      128                  ::1:ipp           :::*
                            tcp    LISTEN     0      100                  ::1:smtp          :::*
                            
                          • 8. TCP Only

                            The -t option can be used to display only TCP sockets. When combined with -l to only print out listening sockets we can see everything listening on TCP.

                            [root@centos7 ~]# ss -lt
                            State      Recv-Q Send-Q      Local Address:Port       Peer Address:Port
                            LISTEN     0      128                     *:sunrpc     *:*
                            LISTEN     0      5           192.168.122.1:domain     *:*
                            LISTEN     0      128                     *:ssh        *:*
                            LISTEN     0      128             127.0.0.1:ipp        *:*
                            LISTEN     0      100             127.0.0.1:smtp       *:*
                            LISTEN     0      128                    :::sunrpc    :::*
                            LISTEN     0      128                    :::http      :::*
                            LISTEN     0      128                    :::ssh       :::*
                            LISTEN     0      128                   ::1:ipp       :::*
                            LISTEN     0      100                   ::1:smtp      :::*
                            
                          • 9. UDP Only

                            The -u option can be used to display only UDP sockets. As UDP is a connection-less protocol, simply running with only the -u option will display no output. We can instead combine this with the -a or -l option to see all listening UDP sockets, as shown below.

                            [root@centos7 ~]# ss -ul
                            State       Recv-Q Send-Q  Local Address:Port       Peer Address:Port
                            UNCONN      0      0                   *:mdns       *:*
                            UNCONN      0      0                   *:kpasswd    *:*
                            UNCONN      0      0                   *:839        *:*
                            UNCONN      0      0                   *:36812      *:*
                            UNCONN      0      0       192.168.122.1:domain     *:*
                            UNCONN      0      0        192.168.1.14:domain     *:*
                            
                          • 10. Unix Sockets

                            The -x option can be used to display unix domain sockets only.

                            [root@centos7 ~]# ss -x
                            Netid  State      Recv-Q Send-Q Local Address:Port           Peer Address:Port
                            u_str  ESTAB      0      0      @/tmp/.X11-unix/X0 27818     * 27817
                            u_str  ESTAB      0      0      @/tmp/.X11-unix/X0 26656     * 26655
                            u_str  ESTAB      0      0       * 28344                     * 26607
                            u_str  ESTAB      0      0       * 24704                     * 24705
                            u_str  ESTAB      0      0      @/tmp/.X11-unix/X0 25195     * 24086
                            u_str  ESTAB      0      0      @/tmp/dbus-CRqRiw6V 28388    * 28693
                            ...
                            
                          • 11. Display All Information

                            the -a option shows all, both listening and non-listening sockets. In the case of TCP this means established connections. This option is useful for combining with others, for instance to show all UDP sockets we can add -a, as by default with just the -u option we don’t see as much information.

                            [root@centos7 ~]# ss -u
                            Recv-Q Send-Q       Local Address:Port           Peer Address:Port
                            0      0             192.168.1.14:56658          129.250.35.251:ntp
                            
                            [root@centos7 ~]# ss -ua
                            State       Recv-Q Send-Q  Local Address:Port           Peer Address:Port
                            UNCONN      0      0                   *:mdns           *:*
                            UNCONN      0      0           127.0.0.1:323            *:*
                            ESTAB       0      0        192.168.1.14:56658          129.250.35.251:ntp
                            UNCONN      0      0                   *:21014          *:*
                            UNCONN      0      0                   *:60009          *:*
                            UNCONN      0      0       192.168.122.1:domain         *:*
                            UNCONN      0      0            *%virbr0:bootps         *:*
                            UNCONN      0      0                   *:bootpc         *:*
                            UNCONN      0      0                 ::1:323           :::*
                            UNCONN      0      0                  :::43209         :::*
                            
                          • 12. Show Socket Memory Usage

                            The -m option can be used to display the amount of memory that each socket is using.

                            [root@centos7 ~]# ss -ltm
                            State      Recv-Q Send-Q                Local Address:Port       Peer Address:Port
                            LISTEN     0      128                               *:sunrpc     *:*
                              skmem:(r0,rb87380,t0,tb16384,f0,w0,o0,bl0)
                            LISTEN     0      5                     192.168.122.1:domain     *:*
                              skmem:(r0,rb87380,t0,tb16384,f0,w0,o0,bl0)
                            LISTEN     0      128                               *:ssh        *:*
                              skmem:(r0,rb87380,t0,tb16384,f0,w0,o0,bl0)
                            LISTEN     0      128                       127.0.0.1:ipp        *:*
                              skmem:(r0,rb87380,t0,tb16384,f0,w0,o0,bl0)
                            LISTEN     0      100                       127.0.0.1:smtp       *:*
                              skmem:(r0,rb87380,t0,tb16384,f0,w0,o0,bl0)
                            
                          • 13. Show Internal TCP Information

                            We can request additional internal TCP information with the -i info option.

                            [root@centos7 ~]# ss -lti
                            State      Recv-Q Send-Q                Local Address:Port                        Peer Address:Port
                            LISTEN     0      128                               *:sunrpc                                    *:*
                              cubic rto:1000 mss:536 cwnd:10 lastsnd:373620 lastrcv:373620 lastack:373620
                            LISTEN     0      5                     192.168.122.1:domain                                    *:*
                              cubic rto:1000 mss:536 cwnd:10 lastsnd:373620 lastrcv:373620 lastack:373620
                            LISTEN     0      128                               *:ssh                                       *:*
                              cubic rto:1000 mss:536 cwnd:10 segs_in:2 lastsnd:373620 lastrcv:373620 lastack:373620
                            LISTEN     0      128                       127.0.0.1:ipp                                       *:*
                              cubic rto:1000 mss:536 cwnd:10 lastsnd:373620 lastrcv:373620 lastack:373620
                            LISTEN     0      100                       127.0.0.1:smtp                                      *:*
                              cubic rto:1000 mss:536 cwnd:10 lastsnd:373620 lastrcv:373620 lastack:373620
                            

                            Underneath each listening socket we can see additional information. Note that the -i option does not work with UDP, if you instead specify -u instead of -t this extra information will not be present.

                          • 14. Show Summary

                            We can see a quick overview of the statistics with the -s option.

                            [root@centos7 ~]# ss -s
                            Total: 1253 (kernel 1721)
                            TCP:   13 (estab 1, closed 2, orphaned 0, synrecv 0, timewait 0/0), ports 0
                            
                            Transport Total     IP        IPv6
                            *   1721      -         -
                            RAW     1         0         1
                            UDP     9         7         2
                            TCP     11        6         5
                            INET    21        13        8
                            FRAG    0         0         0
                            

                            This quickly allows us to see things like the total number of established connections, as well as counts of each type of socket and whether IPv4 or IPv6 is in use.

                          • 15. Filter Based On State

                            We can specify the state of a socket to only print out sockets in this state. For example we can specify states including established, syn-sent, syn-recv, fin-wait-1, fin-wait-2, time-wait, closed, closed-wait, last-ack, listen and closing. The below example shows all established TCP connections. To generate this I was connected to the server by SSH and just loaded a web page from Apache. We can then see that the connections to Apache quickly change to time-wait.

                            [root@centos7 ~]# ss -t state established
                            Recv-Q Send-Q               Local Address:Port           Peer Address:Port
                            0      64                     192.168.1.14:ssh         192.168.1.191:57091
                            0      0              ::ffff:192.168.1.14:http   ::ffff:192.168.1.191:57373
                            0      0              ::ffff:192.168.1.14:http   ::ffff:192.168.1.191:57372
                            
                            [root@centos7 ~]# ss -t state time-wait
                            Recv-Q Send-Q               Local Address:Port           Peer Address:Port
                            0      0              ::ffff:192.168.1.14:http   ::ffff:192.168.1.191:57373
                            0      0              ::ffff:192.168.1.14:http   ::ffff:192.168.1.191:57372
                            
                          • 16. Filter Based On Port Number

                            Filtering can also be performed to list all ports that are less than (lt), greater than (gt), equal to (eq), not equal to (ne), less than or equal to (le), or greater than or equal to (ge).

                            For example, the below command shows all listening ports on port number 500 or below.

                            [root@centos7 ~]# ss -ltn sport le 500
                            State       Recv-Q Send-Q    Local Address:Port      Peer Address:Port
                            LISTEN      0      128                   *:111       *:*
                            LISTEN      0      5         192.168.122.1:53        *:*
                            LISTEN      0      128                   *:22        *:*
                            LISTEN      0      100           127.0.0.1:25        *:*
                            LISTEN      0      128                  :::111       :::*
                            LISTEN      0      128                  :::22        :::*
                            LISTEN      0      100                 ::1:25        :::*
                            

                            For comparison we can perform the opposite, and view all ports greater than 500 with ‘gt’

                            [root@centos7 ~]# ss -ltn sport gt 500
                            State       Recv-Q Send-Q    Local Address:Port       Peer Address:Port
                            LISTEN      0      128           127.0.0.1:631        *:*
                            LISTEN      0      128                 ::1:631        :::*
                            

                            We can also filter based on items such as source or destination port, for example below we search for TCP sockets that have a source port (sport) of ssh.

                            [root@centos7 ~]# ss -t '( sport = :ssh )'
                            State       Recv-Q Send-Q       Local Address:Port         Peer Address:Port
                            ESTAB       0      64             192.168.1.14:ssh        192.168.1.191:57091
                            
                          • 17. Show SELinux Context

                            The -Z and -z options can be used to show the SELinux security context of a socket. In the example below we also use the -t and -l options to only list listening TCP sockets, with the -Z option we can also see the SELinux contexts.

                            [root@centos7 ~]# ss -tlZ
                            State      Recv-Q Send-Q     Local Address:Port     Peer Address:Port
                            LISTEN     0      128                    *:sunrpc     *:*                users:(("systemd",pid=1,proc_ctx=system_u:system_r:init_t:s0,fd=71))
                            LISTEN     0      5          192.168.122.1:domain     *:*                users:(("dnsmasq",pid=1810,proc_ctx=system_u:system_r:dnsmasq_t:s0-s0:c0.c1023,fd=6))
                            LISTEN     0      128                    *:ssh        *:*                users:(("sshd",pid=1173,proc_ctx=system_u:system_r:sshd_t:s0-s0:c0.c1023,fd=3))
                            LISTEN     0      128            127.0.0.1:ipp        *:*                users:(("cupsd",pid=1145,proc_ctx=system_u:system_r:cupsd_t:s0-s0:c0.c1023,fd=12))
                            LISTEN     0      100            127.0.0.1:smtp       *:*                users:(("master",pid=1752,proc_ctx=system_u:system_r:postfix_master_t:s0,fd=13))
                            
                          • 18. Display Version

                            The -v option can be used to display specific version information for the ss command, in this instance we see the version of the iproute package which provides ss.

                            [root@centos7 ~]# ss -v
                            ss utility, iproute2-ss130716
                            
                          • 19. Print Help Documentation

                            The -h option can be used to display further help regarding the ss command, it’s good to use as a quick reference if you need a short description on some of the most commonly used options. Note that the full output here has not been included for brevity.

                            [root@centos7 ~]# ss -h
                            Usage: ss [ OPTIONS ]
                            
                          • 20. Show Extended Information

                            We can use the -e option which shows extended detailed information, as shown below we can see the extended information appended to the end of each line.

                            [root@centos7 ~]# ss -lte
                            State      Recv-Q Send-Q      Local Address:Port         Peer Address:Port
                            LISTEN     0      128                     *:sunrpc       *:*                 ino:16090 sk:ffff880000100000 <->
                            LISTEN     0      5           192.168.122.1:domain       *:*                 ino:23750 sk:ffff880073e70f80 <->
                            LISTEN     0      128                     *:ssh          *:*                 ino:22789 sk:ffff880073e70000 <->
                            LISTEN     0      128             127.0.0.1:ipp          *:*                 ino:23091 sk:ffff880073e707c0 <->
                            LISTEN     0      100             127.0.0.1:smtp         *:*                 ino:24659 sk:ffff880000100f80 <->
                            
                          • 21. Show Timer Information

                            The -o option can be used to display the timer information. This information shows us things such as the retransmission timer value, number of retransmissions that have occurred, and the number of keepalive probes that have been sent.

                            [root@centos7 ~]# ss -to
                            State       Recv-Q Send-Q         Local Address:Port             Peer Address:Port
                            ESTAB       0      64              192.168.1.14:ssh              192.168.1.191:57091      timer:(on,242ms,0)
                            ESTAB       0      0        ::ffff:192.168.1.14:http      ::ffff:192.168.1.191:57295      timer:(keepalive,120min,0)
                            ESTAB       0      0        ::ffff:192.168.1.14:http      ::ffff:192.168.1.191:57296      timer:(keepalive,120min,0)
                            
                          • behrooz mohamadi nsasab
                          ۰۳
                          اسفند
                          در این آموزش می‌خواهیم هارد سرور 192.168.200.3 را به کلاینت 192.168.200.2 بعنوان پارتیشن لوکالی معرفی نماییم.
                          نیازمندی:
                          در سرور: نصب بسته  nfs-kernel-server
                          در کلاینت :‌نصب بسته  nfs-common

                          در سرور (192.168.200.3):
                          1-$ sudo apt-get update
                          2-$ sudo apt-get install nfs-common
                          3- create one DIRECTORY to share
                          4- sudo chown nobody:nogroup DIRECTORY
                          5- sudo nano /etc/exports
                          6- DIRECTORY       192.168.200.2(rw,sync,no_root_squash,no_subtree_check)
                          directory_to_share       client(share_option1,...,share_optionN)
                          7- sudo exportfs -a
                          8- sudo service nfs-kernel-server start



                          در کلاینت (192.168.200.2)
                          1- sudo apt-get update
                          2- sudo apt-get install nfs-common
                          3-create MountPoint
                          4- sudo mount 192.168.200.3:DIRECTORY    #Directory on server 192.168.200.3
                          5- df -h
                          6- sudo mount -a
                          for permanently mount:
                          7-vim /etc/fstab
                          8- 192.168.200.3:DIRECTORY    MountPoint   nfs auto,noatime,nolock,bg,nfsvers=4,intr,tcp,actimeo=1800 0 0

                          LINK
                          • behrooz mohamadi nsasab
                          ۲۲
                          بهمن

                          1-IP(OnBoot-Permanent)-dhcp-debian

                           

                            vim /etc/network/interfaces
                            • auto eth0
                            • iface eth0 inet dhcp
                            sudo /etc/init.d/networking restart

                               

                              2-IP(OnBoot-Permanent)-static-debian

                               

                                vim /etc/network/interfaces
                                • auto eth0
                                • iface eth0 inet static
                                • address 192.168.50.2
                                • netmask 255.255.255.0
                                • gateway 192.168.50.1
                                • dns-nameservers 192.168.200.1
                                sudo /etc/init.d/networking restart

                                   

                                  3-IP(OnBoot-Permanent)-dhcp-redhat

                                   

                                   

                                    vim /etc/sysconfig/network-scripts/ifcfg-eth0
                                    • DEVICE=eth0
                                    • TYPE=Ethernet
                                    • ONBOOT=yes
                                    • BOOTPROTO=dhcp
                                    • IPV4_FAILURE_FATAL=yes
                                    • NAME="System eth0"

                                    service network restart

                                    or

                                    nmcli dev disconnect ${device}
                                    nmcli con reload ${device}
                                    nmcli con up ${device}

                                    4-IP(OnBoot-Permanent)-static-redhat

                                     

                                      vim /etc/sysconfig/network-scripts/ifcfg-eth0
                                      • DEVICE="eth0"
                                      • BOOTPROTO=static
                                      • ONBOOT=yes
                                      • TYPE="Ethernet"
                                      • IPADDR=192.168.50.2
                                      •  NAME="System eth0"
                                      •  HWADDR=00:0C:29:28:FD:4C
                                      • GATEWAY=192.168.50.1
                                      • [PEERDNS=no  (then add DNS to /etc/resolv.conf)]
                                      •  or [DNS1=8.8.8.8] and 
                                      • [DNS2=8.8.4.4]]

                                      service network restart

                                      or

                                      nmcli dev disconnect ${device}
                                      nmcli con reload ${device}
                                      nmcli con up ${device}

                                      5-VirtualIP-(OnBoot-Permanent)-debian-static

                                       

                                        vim /etc/network/interfaces [append]
                                        • iface eth0:0 inet static
                                        • address 123.123.22.22
                                        • netmask 255.0.0.0
                                        • broadcast 123.255.255.255
                                        /etc/init.d/networking restart

                                           

                                           

                                          6-VirtualIP-(OnBoot-Permanent)-debian-DHCP

                                            vim /etc/network/interfaces [append]
                                            • iface eth0:0 inet dhcp
                                            /etc/init.d/networking restart

                                               

                                              7-virtualIP-(OnBoot-Permanent)-Redhat-static

                                               

                                                vim  /etc/sysconfig/network-scripts/ifcfg-eth0:0
                                                • DEVICE=eth0:0
                                                • IPADDR=123.123.22.22
                                                • NETMASK=255.0.0.0
                                                • NETWORK=123.0.0.0
                                                • BROADCAST=123.255.255.255
                                                • ONBOOT=yes

                                                service network restart

                                                or

                                                nmcli dev disconnect ${device}
                                                nmcli con reload ${device}
                                                nmcli con up ${device}

                                                 

                                                8-virtualIP-(OnBoot-permanent)-Redhat-DHCP

                                                 

                                                  vim  /etc/sysconfig/network-scripts/ifcfg-eth0:0
                                                  • DEVICE=eth0:0
                                                  • BOOTPROTO=dhcp
                                                  • ONBOOT=yes

                                                  service network restart

                                                  or

                                                  nmcli dev disconnect ${device}
                                                  nmcli con reload ${device}
                                                  nmcli con up ${device}

                                                   

                                                  9-IP(Not permanent)-ifconfig

                                                  • ifconfig -a                                                               #show all Interface and details
                                                  • ifconfig enp6s0 down                                            #set off interface
                                                  • ifconfig enp6s0 up                                                 #set on interface
                                                  • ifconfig enp6s0 192.168.2.24                                #set ip to interface
                                                  • ifconfig enp6s0 netmask 255.255.255.0                #set subnetmask
                                                  • ifconfig enp6s0 mtu 9000                                      #set mtu
                                                  • ifconfig enp6s0:0 192.168.2.25                             #set secondary ip (virtual)
                                                  • ifconfig eth0:0 down                                              #set off virtual ip
                                                  •  

                                                   

                                                  10-IP(Not permanent)-ip

                                                  • ip a                                                                         #show all Interface and details
                                                  • ip link set eth0 down                                             #set Off interface
                                                  • ip link set eth0 up                                                  #set on interface
                                                  • ip addr add 192.168.2.24/24 dev eth0                    #set ip to interface
                                                  • ip link set eth0 mtu 9000                                       #set mtu
                                                  • ip addr del 192.168.1.1/24 dev eth0                       #set Off interface
                                                  • ip addr show eth0
                                                   
                                                   
                                                   

                                                  نکته: از دستور زیر برای استفاده در توزیع‌های ردهت استفاده می‌شود:

                                                  system-config-network-tui
                                                  نکتنه: میتوانیم با دستور زیر برنامه‌ای در CentOS6 نصب کنیم تا بتوانیم توسط آن کارت شبکه را تنظیم نماییم:
                                                  yum intall system-config-network
                                                  • behrooz mohamadi nsasab
                                                  ۲۲
                                                  بهمن
                                                  می‌توان آدرس مک(یا همان physical address) یک اینتر فیس را تغییر داد
                                                  ifconfig eth0 hw ether AA:BB:CC:DD:EE:FF

                                                  • behrooz mohamadi nsasab