Transcript for:
Linux Network & System Commands

if you need to make changes to IP addresses or configurations of your network adapter inside of Linux then you'll need to use the IP command From here you can enable an interface disable an interface or make changes to the configuration of your network settings To view your current IP configuration you can use the IP address command This shows you a breakdown of IP addresses separated by the interfaces inside of your Linux device If you want to view routing tables you can use IP route And if you need to configure an IP address on an interface there's a single command line for IP address and then the parameters that you'd like to update It's always a challenge when you sit down at a new computer and you're not quite sure what the IP address configuration is of this device So on this Linux machine we will use the IP address command and it shows us that there are two separate interfaces on this device Interface one is a loop back address and it shows all the loop back address information Since this is a loop back address it will always have an address on the 127 network and the default IP address for most devices is 127.0.0.1 There's also a second address This is the primary Ethernet adapter on this device This is adapter ENP05 and it has an IP address of 10.21155.20 20 with a subnet mask of /24 The broadcast address is 10.211.55.255 and you can view MAC information here There's also IPv6 information displayed as well If there are multiple adapters inside of this computer we will see the IP address configuration for each of those by running the IP address command If you're a system administrator of other operating systems then you're probably already familiar with the ping command Ping command is an almost universal command that's used across many different operating systems to be able to query a device across the network and see if you can get a response This is usually one of the first things you do when you're troubleshooting the network You use the ping command to see if you can get a response from that remote device The syntax of the ping command is very similar to almost any other operating system We type ping and then we specify an IP address that we would like to access Let's say in this case that we would like to see if device 99.9 is going to respond to us across the internet That is for the Quad9 DNS service And if we hit enter it begins the process of pinging Quad9 It sends 56 bytes of data by default We get information saying that we are receiving responses from that device We can see sequence numbers time tolive information and roundtrip time for this ping Unlike other operating systems you'll notice that the ping command in Linux will continue to ping every second until you use the control C command and interrupt the process At that point it gives us a summary saying that we've sent 26 packets that we have also received 26 packets There's been zero packet loss because of that and this occurred over a time frame of 25,000 milliseconds which is 25 seconds The roundtrip time minimums averages maximums and deviations are also listed at the bottom You can see that our minimum time was 35 milliseconds The average was 35 The maximum was 36.8 and we have a standard deviation of450 milliseconds When you're working at the command line there's obviously no graphical browser that you can use to access a website but there are ways to request and receive information from a web server using HTML at the command prompt and the utility curl Curl stands for client URL And we're able to retrieve data from that device using a specific uniform resource locator This allows us to access a web page or even other devices using this curl utility Once we receive all of the raw data or the raw HTML from that website you can then search through that information parse out any details or even use this as part of an automated script If you're using a graphical browser you can specify a website like www.professormeser.com and you can view the information associated with that website But at the command prompt there is no graphical browser So we will use the curl command and I will specify www.professormemeser.com and the information that we receive in the terminal screen is the raw HTML that would normally be rendered by your graphical browser But since we have access now to the raw HTML we can search through this data We can parse information We can look and see what may be really being transferred across the network And this shows us a raw data view of the entire web page When you're troubleshooting network problems you might also be troubleshooting issues communicating to a DNS server One way that you can run commands to see what type of response you would get from that DNS server is to use the dig utility If you're a Windows user then you're probably familiar with NSOKUP The dig command is very similar to the functionality of nsookup although the resulting output is slightly different Let's use dig to find the IP addresses associated with my website We'll use the dig command and then we'll specify www.professor messor.com and we'll hit enter And when we do that it gives us a series of output messages associated with our request The first is the dig version that we're using And you can see that we're using this to find www.professor messor.com It tells us that the request that we made or the question that was posed was for that fully qualified domain name And by default I was asking for the internet address That's the in and the A associated with that question The next section is the answer section And you can see that there are three separate IP addresses that were returned from the DNS server ProfessorMasser.com can be found at 104.22.72.108 172.67.41.114 and 104.22.73.108 By design there are multiple points of presence on the internet that will allow you to connect to our web server So depending on where you are in the world you may have a different IP address And occasionally you will see more than one IP address resolved to a single fully qualified domain name and that's provided for redundancy If you're not able to connect to the first IP address there are two other IP addresses that will get you to www.professormeser.com Earlier we were able to ping the Quad9 DNS server across the internet To be able to communicate to that server we had to hop through a number of different routers between my device and the Quad9 servers If you would like to see every router that exists between here and that Quad9 server you can use the trace route command This will map the entire path that a packet takes between our device and that remote location and tell us the IP address of every router along the way If you're a Windows user you've probably run a trace route using trace RT But if you're in Linux Unix or Mac OS you use the full name of trace route Trace route uses something called a time tolive exceeded message to be able to build this table of different routers between two points When we want to know what the first router is trace route uses a time to live of one When we want to know what the second hop might be it uses a time to live of two Notice that the time to live is referring to the number of hops It's not referring to a time of day or the number of minutes or seconds that it takes to communicate across the network Another challenge you'll run into is that many devices will filter the time to live exceeded messages that are received back So if you're working with a firewall that filters out those ICMP messages or the router itself that you're communicating with will not send back a time exceeded message then that is a piece of information that will be dropped from the trace route results Let's run a trace route to my web server So we'll run trace route www.professor professor messor.com and we'll have it go through the trace route process This will run relatively quickly Although you'll notice that there are certain hops along the way where we do not receive a message back from that router Specifically we did lose two of those messages on hop three and we didn't get any information from hop 5 If we look at the results of this trace route we can see there are 10 hops between our device and the IP address associated with www.professormes professor messor.com In this case it has found that IP address to be 104.22.73.108 And since we have a number of different points of presence around the world that IP address might change depending on where you happen to be In each one of these hops you'll notice there is an IP address That's the IP address of the router at that hop And then there are three separate measurements These are roundtrip time measurements to that particular router By default trace route performs each check three times to every hop You can of course modify these configuration options within the trace route command line but by default this gives you the overview of what you might need to be able to determine how many routers there might be between one device and another If you've downloaded Linux to use on your own system then you already know the download did not include any type of separate documentation Instead the documentation that you need for Linux is built into the operating system itself And to access those manuals you would use the man command Simply use man and the name of the command that you would like to reference and it will provide all of the documentation for that particular command For example we just ran the trace route command but there must have been other parameters that we could have chosen and we can find those by typing the man option and the name of the utility In this case it's trace route And when we hit enter it shows us the reference manual for trace route Tracing the route to a host Shows all of the different command line options And if I use an arrow down I can go a line at a time Or if I use the space bar I can go a page at a time You can also use the arrow keys or the page up and page down to move back and forth through the manual information For instance you could have used the -f command to specify the first hop of a trace route You can choose the method the port number that's being used Remember earlier when I mentioned that trace route goes through each individual hop three times You can modify that number with the -ashq option And you have information here that can change the way the output is shown on the trace route command When you're finished reading through the man page it tells you that you can press H for help or Q to quit And since we're done we press Q and we're back to where we started The term concatenate means to link together in a series and there is a concatenate command inside of Linux and it is abbreviated to cat The cat command allows you to view information in a file and put that information on the screen Or you could also take multiple files and then move them into a third file using a redirect such as the greater than sign Let's try that at our prompt on our Linux machine On our Linux device we have three files 1.ext 2.ext and three.ext And if we cat one.ext you'll see that it simply contains the number one and the letters spelled out one O N E If we cat two.ext it has a similar output Has the number two and then spelled out the word two And then if we cat three.ext it has the number three and it spells out the word three We might want to have all of this information in one single file So we can use the cat command and then specify 1.ext 2.ext and 3.ext And then use the greater than sign to concatenate all of these into all.ext And we'll hit enter Notice we simply get a prompt back meaning that this particular concatenation is complete Now if we cat allt you'll notice it is a single file that contains the number one one number two with two and number three with three We've successfully concatenated all three of those files into one single file We're often called on as technicians to troubleshoot performance problems on a device If you're in Windows you've probably used Task Manager to view the CPU utilization or disk access to a particular system Or maybe you want to see just how much network traffic is being transferred If you're a Windows administrator then you've probably used Windows Task Manager to be able to view CPU information or information on how each individual process is performing There's a similar function within Linux known as top This will show you information on all of the processes running on your system and how much CPU memory and other resources each process may be using You also get a summary of the load on your system presented as three separate numbers The first number is the load over 1 minute The second is the load over the last 5 minutes and the third is the load over the last 15 minutes This is another one of those utilities that has many different options available to it So if you want to customize top to provide information that you'd like to see make sure you check out the man pages for the top utility Running top is as simple as typing to OP and hitting enter And now we can see a 1 second update of what's running on our system We can view information by user the process ID looking at memory information CPU details and how much time each individual process has spent in the CPU This gives us immediate feedback on what's happening inside of our system and we're able to narrow down what processes may be using more resources than another If you would prefer a single textbased output of all of these processes you can view that using the ps command This is also very similar to what you would find in the Windows Task Manager because it will list out all of the process IDs and then all of the process names themselves If you just want to see the processes associated with your login you simply use the ps command But as the administrator you might want to view all of the processes running on this machine And you can use the PS with the -ashe option to view all processes If you run the ps command by itself you're only looking at the processes for the current loggedin user And I have a bash shell That is the terminal screen that I have up And I ran the ps command inside of that bash shell If we use the ps command with the dash e we're now viewing the processes for everything on the system And you can see there are pages and pages of processes You can also pipe this output to the more command which will pageionate this So you can go a page at a time to see all the processes without them going by all at once But if you're looking for a very specific process you might want to use the ps command with the e and then pipe it to the gp command and then specify a search term In this case let's look for all of the processes that have the search term CPU as part of the process And you can see that we have four that showed up There was process 20 which is CPU HP/Z process 21 which is CPUHP1 And you can see two other processes that have the word CPU as part of the process name If you're like me you probably don't have a lot of free drive space on your computer And if you're planning to perform an update or you want to install a new application it might be good to see if you have enough space to be able to perform that function In Linux the way that we view this is with the DF command That stands for disk free It will show us all the file systems and how much space might be available on each file system The default is to use DF with no parameters And this shows us the usage based on number of blocks In this case 1K blocks If you'd like a view that showed it as number of bytes you could use the same df command with a -h to get a human readable view This will show the output with gigabytes megabytes and other human readable values Let's run the df command on my machine I'm going to specify -h because I like to see this listed as megabytes gigabytes and other familiar values You can see that I have a number of file systems that are mounted on this computer I have one that is a temporary file system It has a size of 196 megabytes I'm only using 1.7 megabytes so that 194 megabytes are available which means I'm only using 1% of my temp fs file space I have other things that are connected to this computer For example I have T4 V3 This has a volume size of 3.7 tab I'm using 1.9 tab which means that 1.8 tab is available So I'm using approximately 52% of that particular file system So if we need to install some additional software we might want to avoid the file systems with over 90% utilization and instead use one of these file systems that has much more space available The natural next question when you find a file system that has very little space available is what is taking up all of that room on the file system it may be a single file It may be multiple files But we need to determine how we might be able to free up some space on that particular partition One way that you could find out what's using that space is by using the du command for disk usage This will scan your current folder and all of the subdirectories underneath and it will show you exactly how much space is being used in each individual folder If you're looking to find how you can easily free up some space this utility should be the one you run And I would recommend running it with the -h option so that you get human readable output I'm going to run the du command with that -h option I'm going to pipe the whole thing to more so that you can get an idea of just how much information is shown to the screen And it starts going through the local directory and finding all of the files that are stored in that local directory This starts going through all of the individual directories on a particular system one by one and provides you with a summary of how much space is being used Let's hit the space bar to go to the next page Almost everything here is a relatively small number Here's one that's relatively large It's 1.4 megabytes We have others that are 12 megabytes These are 28 megabytes So now we can start getting an idea of where the space is really being used and we might want to go to the old Firefox data that is in our directory that's taking up 70 megabytes and start deleting those directories to free up some room A lot of the configurations in Linux are stored in text files and if you need to modify or change an application or something in the operating system you need to modify that text file Fortunately Linux comes with a number of different text editors One of the more popular is Nano This is a full screen text editor and you can run it in your terminal screen You may find that Nano is already installed in your current Linux distribution or you can install it using the package manager on your system This full screen text editor allows us to use functions that normally would not be available at the command line such as marking and selecting copying information pasting it somewhere else and giving us features that you would normally find in a graphical text editor On my Linux distribution I have a file that I would like to edit This is the O.log file You can see it's 27K in length This would not be something that would be very easy to update or modify without some type of editor So we'll use nano and we'll specify o.log This brings up a full screen editor And if you've done any type of editing from a graphical editor or full screen in Linux this should be very familiar to you You can move around with your cursor keys You can type in at any of these prompts and you have commands across the bottom where you can save the file get additional help copy cut replace and perform other functions inside of this text editor When you're done you can choose the Ctrl X option to exit out Since I've made changes to this file it asks if I'd like to save this information In this case since I did not put anything in here that I'd like to save I'll simply choose no And we're back at our command prompt Nano is just one of many text editors that you could run inside of your Linux operating system But since Nano is commonly installed with most distributions it's probably already going to be available to you