Computer Networks Lab 2

Index

Content

Installing Packages

To install packages on a Debian-based system like Ubuntu, you can use the apt-get command with sudo to gain administrative privileges. The general syntax is:

sudo apt-get install package_name

For example, to install the curl package, you would use:

sudo apt-get install curl

Updating Applications

To keep your system and applications up to date, you can use the apt-get commands:

  1. Update the package lists:
sudo apt-get update
  1. Upgrade the installed packages to their latest versions:
sudo apt-get upgrade
  1. For a more comprehensive upgrade that handles changing dependencies:
sudo apt-get dist-upgrade

For an advanced guide checkout Package Managers.

Using gedit

gedit is a simple text editor for the GNOME desktop environment. You can use it to create and edit text files. To open gedit, use the following command:

gedit filename

If the file does not exist, gedit will create it for you. For example, to create or edit a file named example.txt:

gedit example.txt

Writing and Running a Hello World C Program

You can write and compile a simple C program using the terminal. Follow these steps:

  1. Create the C program file:
gedit hello.c
  1. Write the Hello World program:
#include %3Cstdio.h%3E
 
int main() {
    printf("Hello, World!\n");
    return 0;
}

Save and close the file.

  1. Compile the program using gcc:
gcc hello.c -o hello
  1. Run the compiled program:
./hello

You should see the output:

Hello, World!

Using Ping

ping is a network utility used to test the reachability of a host on an IP network. It sends ICMP Echo Request messages and listens for ICMP Echo Reply messages.

To ping a host, use the command:

ping hostname_or_ip

For example, to ping Google’s DNS server:

ping 8.8.8.8

Using Ipconfig

On Unix-based systems, the equivalent of ipconfig on Windows is ifconfig or ip. These commands display the network configuration.

  • Using ifconfig:
ifconfig
  • Using ip:
ip addr show

Saving Output to a Text File

You can save the output of any command to a text file using the > or >> operators.

  • > will overwrite the file with the new content.
  • >> will append the new content to the end of the file.

For example, to save the output of ifconfig to network_info.txt:

ifconfig > network_info.txt

To append the output of ping to the same file:

ping 8.8.8.8 >> network_info.txt

References

Add the rest of to the unix book guide