Lesson 5

Dates: 6/5/2019
Linux networking
Linux System Administration

Exercises: send/receive data with netcat

Netcat is a very useful tool to connect to any TCP and UDP port on a remote host, and send/receive data.

  • Start both, kvm3 and CentOS7 VMs:
    virsh start kvm3
    virsh start CentOS7
  • Login to console of kvm3:
    virsh console kvm3
  • Bring up another command prompt on the desktop and login to CentOS7
    virsh console CentOS7
  • On each VM, execute command ip addr show to read the IP address:
    ip addr show eth0
  • Become root on both the VMs
    sudo -s

    1. Install netcat on kvm3:
    apt-get install netcat

    2. Start netcat as a server, listening on port UDP/8080
    netcat -l -u 8080

    3. When the session is over, type Ctrl-C to stop the netcat server.

    4. Start the server on TCP/8080 to write into a file, outputfile.txt :
    netcat -l 8080 > outputfile.txt

    5. After the file is received, the connection closes itself.
    Check the content of the file:
    less outputfile.txt 
    1. Install netcat on CentOS7:
    yum install nmap-ncat

    2. By using ncat, connect to UDP/8080 port on kvm3,
    ncat -u 8080

    3. Start typing text. Hit ENTER key. The text should appear on the both terminals. Press Ctrl+D to close the UDP connection.

    4. Send file /etc/hosts to TCP/8080 on kvm3 VM via netcat:
    ncat  8080 < /etc/hosts

  • Take me to the Course Website