If you own an iMac you understand the frustration of not having the built in hardware functioning as expected. In fact, hardware failure is an unexpected event with Apple products, so when that happens, the solution can be tasking.
To resolve the issue of a failed Ethernet port you should first check the hardware before resolving to replace it. The easiest way is to click on the Apple icon in the upper left corner and select About this Mac. Then click on the More Info button. You will get a list of items associated with the system, including the Ethernet Card. Highlight that item and see if the system recognizes the device. If you see, on the right side of the screen, The Computer does not seem to have an Ethernet pci card installed, then the port probably went bad and needs to be replaced. If your system is under warranty you should take it back to the Apple store and have it fixed. (Remember to always back up your data prior to handing it over)
If you do not want to go through the hassle of taking the system to the Apple Store, or do not have time, you can install a Thunderbolt to Ethernet adapter. Typically around thirty dollars, the device plugs into one of the two Thunderbolt ports on the back of the iMac. Plug the Ethernet cord into the Thunderbolt device and you should be online! Done.
Note: If you see the device in the hardware list, yet it is not accessing the internet, try a different Ethernet port on the router or modem, try a different cable or try plugging directly into the router or modem and not through a port in the wall, (if that is the case). If you have wireless access try to that connection and determine if the speed is acceptable.