meta data for this page
  •  

Különbségek

A kiválasztott változat és az aktuális verzió közötti különbségek a következők.

Összehasonlító nézet linkje

Előző változat mindkét oldalonElőző változat
Következő változat
Előző változat
linux:network [2019/01/24 11:00] adminlinux:network [2024/03/21 16:49] (aktuális) admin
Sor 1: Sor 1:
 ====== Hálózati okosságok ====== ====== Hálózati okosságok ======
 +
 +==== File letöltő BASH-sel ====
 +
 +<file>
 +#!/bin/bash
 +# Usage: ./download_file 'https://www.baeldung.com/java-weekly-495' 'java_weekly_495.html'
 +raw_download() {
 +    wPROTO="${1%://*}"
 +    af="${1#*://}"
 +    wBASE="${af%%/*}"
 +    wSUB="${af#*/}"
 +
 +    HTTP_REQUEST="$({
 +        echo -en 'GET /'"${wSUB}"' HTTP/1.1\r\n'
 +        echo -en 'Host: '"${wBASE}"'\r\n'
 +        echo -en 'Connection: close\r\n\r\n'
 +    })"
 +
 +    if [[ "${wPROTO,,}" = 'https' ]] ; then
 +        echo "${HTTP_REQUEST}" | openssl s_client -quiet -connect ${wBASE}:443
 +    else
 +        exec {NFD}<>"/dev/tcp/${wBASE}/80"
 +        echo "${HTTP_REQUEST}" >&"${NFD}"
 +        while read -u "${NFD}" lz; do
 +            echo "${lz}"
 +        done
 +        exec {wFD}>&-
 +    fi
 +}
 +
 +main() {
 +    raw="$(raw_download "${1}" 2>errorlog.txt)"
 +    echo "${raw#*$'\r\n\r\n'}" > "${2}"
 +}
 +
 +main "${@}"
 +</file>
 +
 +==== Rsync ====
 +
 +To create a new directory at the destination and back up your files there, add a trailing slash (/) at the end of the destination path. If you add the trailing slash to the source, then the source directory will not be created at the destination. Rsync only transfers its content in that case.
 +Kulcs használat:
 +
 +  rsync e "ssh -i $HOME/.ssh/somekey"
 +
 +==== Firewalld ====
 +
 +[[https://linuxconfig.org/introduction-to-firewalld-and-firewall-cmd-command-on-linux]]
 +
 +==== Port tesztelés BASH-sel ====
 +
 +/dev/tcp/host/port: (If host is a valid hostname or Internet address, and port is an integer port number or service name, bash attempts to open a TCP connection to the corresponding socket.)
 +
 +/dev/udp/host/port: (If host is a valid hostname or Internet address, and port is an integer port number or service name, bash attempts to open a UDP connection to the corresponding socket.)
 +
 +So you could use something like this:
 +
 +  xenon-lornix:~> cat < /dev/tcp/127.0.0.1/22
 +  SSH-2.0-OpenSSH_6.2p2 Debian-6
 +  ^C pressed here
 +
 +Szkriptbe:
 +
 +  (echo > /dev/tcp/localhost/1500) >/dev/null 2>&1 && echo "It's up" || echo "It's down"
 +  timeout 1s bash -c "true <>/dev/tcp/localhost/443" >/dev/null 2>&1 && echo "It's up" || echo "It's down"
 +  while [[ -n $((echo > /dev/tcp/$TCPS/$TCPP) 2>&1 > /dev/null) ]]; do echo varunk; sleep 10; done
 +
 +nc-vel:
 +
 +  nc -zv hoszt port
 +
 +Windows PowerShell:
 +
 +  Test-NetConnection -ComputerName myserver.com -Port 443
 +==== NFS okosságok ====
 +
 +Portcheck ([[http://bluefinch-nl.blogspot.com/2014/04/mounting-nfs-shares-from-linux-server.html|link]])
  
 ==== SSH okosságok ==== ==== SSH okosságok ====
 +
 +[[linux:ssh-exit-codes.sh|SSH exit kódok]]
  
 === SSH-n másolás köztes állomáson át === === SSH-n másolás köztes állomáson át ===
  
   tar cvf - file1 file2 | ssh KoztesHoszt "ssh -o \"StrictHostKeyChecking no\" CelHoszt \"cd CelMappa && tar -xvf -\""   tar cvf - file1 file2 | ssh KoztesHoszt "ssh -o \"StrictHostKeyChecking no\" CelHoszt \"cd CelMappa && tar -xvf -\""
 +  
 +Kicsit kultúráltabban:
 +
 +~/.ssh/config:
 +
 +<file>
 +Host jumphost1
 +  User username1
 +Host jumphost2
 +  User username2
 +  ProxyCommand ssh -W %h:%p jumphost1
 +Host jumphost3
 +  User username3
 +  ProxyCommand ssh -W %h:%p jumphost2
 +Host server
 +  User username4
 +  ProxyCommand ssh -W %h:%p jumphost3
 +</file>
 +
 +Majd 
 +  ssh/scp server ...
  
 === Több parancs futtatása SSH-n === === Több parancs futtatása SSH-n ===
Sor 35: Sor 135:
       expect eof"       expect eof"
 </file> </file>
 +
 +Az ssh parancs ne hajtsa végre a hibás RC kódú parancs utáni többi parancsot: set -e
 +
 +=== SFTP leírások ===
 +
 +  [[https://serverfault.com/questions/639042/does-openssh-sftp-server-use-umask-or-preserve-client-side-permissions-after-put|File permissions]]
 +  [[https://www.techrepublic.com/article/how-to-set-up-an-sftp-server-on-linux/|How to set up SFTP server on Linux]]
  
 ==== Egyéb okosságok ==== ==== Egyéb okosságok ====
Sor 58: Sor 165:
   ftp> bin   ftp> bin
   ftp> put "| dd if=/dev/zero bs=32k count=10000 " /dev/null   ftp> put "| dd if=/dev/zero bs=32k count=10000 " /dev/null
 +
 +=== Hálózat felderítés ===
 +
 +  nmap -sP hoszt/hálózat
 +
 === Port scanning === === Port scanning ===
  
   nmap -sT hoszt   nmap -sT hoszt
  
-=== FC portok lekérdezése ===+=== Ethernet és FC portok lekérdezése ===
  
 <file> <file>
-#!/bin/sh +#!/bin/bash 
-echo --- BEGIN --- +SEARCH=${1-.} 
-for port in $(ls -/sys/class/fc_host/host*); do +VLAN_SNIFF_TIME=10 
-  echo "$port: " +#ETH 
-  printf "Port state: \t"; cat $port/port_state +echo "Port#Address#Speed#State#VLANs#Slaves" | awk -F'#' '{printf "%-25s | %-17s | %10s | %-10s | %-13s | %-15s\n",$1,$2,$3,$4,$5,$6}' 
-  printf "Port speed: \t"; cat $port/speed +echo "# Ethernet:" 
-  printf "Port WWN: \t"; cat $port/port_name +for ETH in $(ip addr | awk -F': ' '/</{print $2}' | egrep -v '(@|lo|^$)' | grep "$SEARCH" | sort -k1); do 
-  echo -----+        STATE=$(ethtool $ETH 2>/dev/null | awk -F': ' '/Link detected/{print $2}' | sed -e 's/yes/Link UP/' -e 's/no/Link DOWN/'
 +        SPEED=$(ethtool $ETH 2>/dev/null | awk -F': ' '/Speed/{print $2}' | sed 's/^[0-9]*/& /'
 +        MAC=$(ip addr | grep -A1 "[^@]$ETH:"  | grep -o '\([0-9abcdef]\{2\}:\)\{5\}[0-9abcdef]\{2\}' | awk '{print $1}' | grep -v 'ff:ff:ff:ff:ff:ff'
 +        VLANS=$(timeout ${VLAN_SNIFF_TIME} tcpdump -c 1000 -nni $ETH -e vlan 2>/dev/null | grep -o 'vlan [0-9]*' | sort | uniq | awk '/vlan/{print $2}' | tr '\n' ' ') 
 +        SLAVES="
 +        for BOND in `ls /proc/net/bonding/* 2>/dev/null`do 
 +            if [[ $(grep -c "Slave.*$ETH" $BOND) -gt 0 ]]; then 
 +                MAC=$(grep -A5 "Slave.*$ETH" $BOND | tail -n1 | grep -oP '(?<=addr: ).*$'
 +            fi 
 +        done 
 +        if [[ $ETH =~ ^bond ]]; then 
 +                SLAVES=$(awk '/^Slave Interface/{print $3}' /proc/net/bonding/$ETH | tr '\n' ' ') 
 +        fi 
 +        echo "$ETH#$MAC#$SPEED#$STATE#$VLANS#$SLAVES" | awk -F'#' '{printf "%-25s | %-17s | %10s | %-10s | %-13s | %-15s\n",$1,$2,$3,$4,$5,$6}' 
 +done 
 +#FC 
 +echo "# Fiber Channel:" 
 +for PORT in $(ls -d /sys/class/fc_host/host*)do 
 +        STATE=$(cat $PORT/port_state) 
 +        SPEED=$(cat $PORT/speed) 
 +        WWN=$(cat $PORT/port_name | sed 's/^0x//') 
 +        echo "$PORT#$WWN#$SPEED#$STATE" | awk -F'#' '{printf "%-25s | %-17s | %10s | %-10s\n",$1,$2,$3,$4}'
 done done
-echo --- END --- 
 </file> </file>
  
Sor 87: Sor 219:
 </file> </file>
  
 +=== VLAN tag-ek az interfész csomagjain ===
 +
 +  tcpdump -c 1000 -nni bond0 -e vlan | grep -o 'vlan [0-9]*' | sed 's/^.*$/Found & tagged pockets/' | sort | uniq
 +
 +[[http://www.yolinux.com/TUTORIALS/LinuxTutorialNetworking.html#MULTICAST]]
 +
 +[[https://www.aelius.com/njh/subnet_sheet.html|Subnet Mask Cheat Sheet]]